简体   繁体   English

显示阵列/列表的内容

[英]Display content of the array/list

I'm looking for a way to display (in the MsgBox or other read-able place) the array/list content, the list contains only strings: 我正在寻找一种显示(在MsgBox或其他可读位置中)数组/列表内容的方法,该list仅包含字符串:

Dim list As New List(Of String)

I would like to display the content of it in the MsgBox for now. 我现在想在MsgBox显示它的内容。 I can convert the list to the array if there would be a need. 如果需要,我可以将list转换为array Is there a way to do this? 有没有办法做到这一点?

You can declare a variable and loop the array putting every element inside: 您可以声明一个变量并循环将每个元素放入其中的数组:

Dim sResult As String = ""

For Each elem As String In list
    sResult &= elem & " "
Next

Or you can use String.Join() to directly merge all the elements of the array (you will need to convert the List to a normal array if using .NET framework before 4.0): 或者,您可以使用String.Join()直接合并数组的所有元素(如果在4.0之前使用.NET框架,则需要将List转换为普通数组):

Dim sResult As String = String.Join(", ", list.ToArray())

How many elements are in that List? 该列表中有多少个元素? If they are few then a MessageBox could do 如果他们很少,那么MessageBox可以做

Dim message = string.Join(Environment.NewLine, list.ToArray())
MessageBox.Show(message)

If there are many, then you need some kind of interface to display everything. 如果有很多,那么您需要某种界面来显示所有内容。
In this case you need at least a WinForm application with your user defined Form that contains a TextBox with its multiline property set to true. 在这种情况下,您至少需要一个WinForm应用程序,该应用程序的用户定义表单包含一个TextBox,并将其multiline属性设置为true。

Dim message = string.Join(Environment.NewLine, list.ToArray())
textBox1.Text = message

Here a reference to MSDN docs on List(Of T) 这是List(Of T)上MSDN文档的引用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM