none
double[,] a1 = { { 20, 15 }, { 20, 13 } }; 在richtextbox 中怎么输出? RRS feed

答案

  • 你好,

    Thank you for posting in MSDN Forum.

    根据你的描述,在Form中创建一个RichTextBox控件显示相关信息,将a1写入到RichTextBox中,相关代码如下:

    private void Form1_Load(object sender, EventArgs e)
            {
                double[,] a1 =new double[,] { { 20, 15 }, { 20, 13 } };           
                string a1String = "";
                for (int i = 0; i < a1.GetLength(0); i++)
                {
                    for (int j = 0; j < a1.GetLength(1); j++)
                    {
                        a1String += a1[i, j].ToString();
                        a1String += " ";
                    }
                    a1String += Environment.NewLine;
                }      
                richTextBox1.Text = a1String;
            }

    输出二维数组如图所示:

    希望我的回答对你有所帮助,如果有其他相关问题请随时联系我们。

    Best Regards,

    Neda Zhang


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    2016年12月2日 2:53
    版主

全部回复

  • 你好,

    Thank you for posting in MSDN Forum.

    根据你的描述,在Form中创建一个RichTextBox控件显示相关信息,将a1写入到RichTextBox中,相关代码如下:

    private void Form1_Load(object sender, EventArgs e)
            {
                double[,] a1 =new double[,] { { 20, 15 }, { 20, 13 } };           
                string a1String = "";
                for (int i = 0; i < a1.GetLength(0); i++)
                {
                    for (int j = 0; j < a1.GetLength(1); j++)
                    {
                        a1String += a1[i, j].ToString();
                        a1String += " ";
                    }
                    a1String += Environment.NewLine;
                }      
                richTextBox1.Text = a1String;
            }

    输出二维数组如图所示:

    希望我的回答对你有所帮助,如果有其他相关问题请随时联系我们。

    Best Regards,

    Neda Zhang


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    2016年12月2日 2:53
    版主
  • 谢谢
    2016年12月2日 9:33
  • 你好,

    如果问题得到了解决,请将有用的回答标记为答复,我会将解决方案介绍给论坛中遇到相同问题的成员,以便于解决相关问题。如图所示:

    感谢你的参与。

    Best Regards,

    Neda Zhang


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    2016年12月2日 9:38
    版主
  •   string r = "";
                foreach (double i in b1)///这里面的 double 是输出类型,int 为整数
                {
                    r += string.Join("{0} ", i) + "\n";
                }
                richTextBox1.Text = r;

    我用的是这个 比较简便

    2016年12月2日 10:02