素衣清颜淡若尘

c#创建数组的几种写法

电脑版发表于:2020/9/6 22:35

代码如下:

    class Program
    {
        static void Main2(string[] args)
        {
            //写法1
            string[] str2 = new string[3];
            str2[0] = "hello2";

            //写法2
            string[] str = new string[3] { "hello", "word", "sdfs" };

            //方法3
            string[] str4 = new string[] { "hello4", "word", "sdfs" };

            //方法4
            string[] str5 = new[] { "hello5", "word", "sdfs", "sdfs5" };

            //方法5
            string[] str3 = { "hello3" };   

            Console.WriteLine(str[0]);
            Console.WriteLine(str2[0]);
            Console.WriteLine(str3[0]);
            Console.WriteLine(str4[0]);
            Console.WriteLine(str5[0]);

            Console.ReadLine();
        }
    }


关于TNBLOG
TNBLOG,技术分享。技术交流:群号677373950
ICP备案 :渝ICP备18016597号-1
App store Android
精彩评论
{{item.replyName}}
{{item.content}}
{{item.time}}
{{subpj.replyName}}
@{{subpj.beReplyName}}{{subpj.content}}
{{subpj.time}}
猜你喜欢