随着VS2015的发布,C#6.0也到来了。下面来看看他的新特性吧。 1.自动初始化属性(Auto Property Initializer) 自动实现的带有初始值的属性可以不用编写构造器就能被初始化: public class NewAutoProperty
{
public string TestProperty { get; protected set; } = string.Empty;
} 2.主构造器(Primary Consturctor) 主构造器为我们提供了使用参数定义构造器的一个简短语法 public class NewPrimaryConstructors(string testL, int testS, float testC)
{
public string TestL { get; } = testL;
public int TestS { get; } = testS;
public float TestC { get; } = testS;
} 3.字典初始化器(Dictionary Initializer) 使用数组方括号的方式来定义一个字典 public Dictionary<string, string> NewD { get; } = new Dictionary<string, string>()
{
["1"] = "New Dic",
["2"] = "New DicNew Dic"
}; 4.通过命名空间的引用来访问静态类 using System.TestNewClass;
namespace newStaticUsing
{
public class StaticClass
{
public void Test()
{
WriteLine("TestNewClassTestNewClassTestNewClass");
}
}
} 新特性很多,这里就不一一介绍了,有兴趣的看官可以自己去了解了解哈。
|