tnblog
首页
视频
资源
登录

c#创建数组的几种写法

4090人阅读 2020/9/6 22:35 总访问:231573 评论:0 收藏:0 手机
分类: .NET

代码如下:

    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();
        }
    }


评价
旧年素颜,君记否
排名
6
文章
6
粉丝
16
评论
8
{{item.articleTitle}}
{{item.blogName}} : {{item.content}}
ICP备案 :渝ICP备18016597号-1
网站信息:2018-2024TNBLOG.NET
技术交流:群号656732739
联系我们:contact@tnblog.net
欢迎加群交流技术