我可以使用什么代码在文本框或richtextbox中显示两个数组元素(双数据类型) [英] what code can I use to display two array elements(double datatypes) in a textbox or richtextbox

查看:73
本文介绍了我可以使用什么代码在文本框或richtextbox中显示两个数组元素(双数据类型)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用什么代码在文本框或richtextbox中显示两个数组元素(双数据类型),以便两个数组可以采用表格形式。那是

Array1 Array2

0.89 0.21

2.50 3.08。

等到最后一个数组元素。

what code can I use to display two array elements(double datatypes) in a textbox or richtextbox so that the two arrays can be in form of table. That is
Array1 Array2
0.89 0.21
2.50 3.08.
And so on until the last array element.

推荐答案





您可以通过创建字符串并通过循环遍历数组的每个元素来附加每个数组的值来实现您想要的效果。以下是代码:



Hi,

You can achieve what you want by creating a string and appending the values from each array by looping through each element of the array. Here is the code:

double[] array1 = new[] {1.1, 2.2, 3.3};
            double[] array2 = new[] { 4.4, 5.5, 6.7 };
            StringBuilder textBuilder = new StringBuilder();
            int arrayLength = array1.Length;
            for (int loop = 0; loop < arrayLength; loop++)
            {
                textBuilder.Append(array1[loop] + " " + array2[loop] + "\n");
            }
            richTextBox1.Text = textBuilder.ToString();





注意: 为了使这个工作无异常,两个数组的长度应相同。



Note: For this to work without exception both the arrays should be of same length.


听取一个好建议:不要这样做。最好的选择之一是 DataGridView

https://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview%28v=vs.110% 29.aspx [ ^ ]。



-SA
Listen to a good advice: don't do it. One of the best options would be DataGridView:
https://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview%28v=vs.110%29.aspx[^].

—SA


这篇关于我可以使用什么代码在文本框或richtextbox中显示两个数组元素(双数据类型)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆