C#学习系列-String与string的区别

参考:http://www.microsoftvirtualacademy.com/Content/ViewContent.aspx?et=9851&m=9832&ct=31042

如有错误,欢迎指正

String:类,System.String

string:类型,变量

两者本质上没有任何区别,都是System.String,string只是System.String的别名而已

唯一的区别在于如何按照代码约定的来写,如声明变量时使用小写string,使用System.String下方法时使用大写的String

下面贴代码

    class Program
    {
        static void Main(string[] args)
        {
            /*在代码使用上没有任何区别  在使用规范上需要看下是否符合代码约定的规范*/
            Console.WriteLine(typeof(string));
            Console.WriteLine(typeof(String));
            string name1 = "Gerry 1";
            String name2 = "Gerry 2";
            Console.WriteLine(name1);
            Console.WriteLine(name2);
            Console.WriteLine(string.Concat(name1, name2));
            Console.WriteLine(String.Concat(name1, name2));
            Console.ReadLine();
            Console.ReadLine();
        }
    }

作者:释迦苦僧
出处:http://www.cnblogs.com/woxpp
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接。
生活不易,五行缺金,求打点
原文地址:https://www.cnblogs.com/woxpp/p/3907630.html