在C#中,可以使用List来定义一个不固定大小的字符串数组,并通过Add方法插入数据。以下是一个示例:

using System;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        List<string> myArray = new List<string>();

        // 插入数据
        myArray.Add("数据1");
        myArray.Add("数据2");
        myArray.Add("数据3");

        // 输出数组元素
        foreach (string data in myArray)
        {
            Console.WriteLine(data);
        }
    }
}

上述代码定义了一个名为myArray的List对象,使用Add方法向其中插入了三个字符串数据。然后使用foreach循环遍历数组,将每个元素输出到控制台。


原文地址: https://www.cveoy.top/t/topic/pd6U 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录