定义动态数组数组、定义、动态

2023-09-05 02:34:34 作者:把思念活活掐死

我如何定义一个动态数组在C#?

How can I define a dynamic array in C#?

推荐答案

C#不提供动态数组。相反,它提供了其工作方式相同List类。

C# doesn't provide dynamic arrays. Instead, it offers List class which works the same way.

要使用列表,写在你的文件的顶部:

To use lists, write at the top of your file:

using System.Collections.Generic;

和您要使用清单,写(例如对于字符串):

And where you want to make use of a list, write (example for strings):

List<string> mylist = new List<string>();
mylist.Add("First string in list");