做为全球第一的IDE,VS用起来天然至关的爽,当你在visual studio里敲出几个字母,能帮你生成一大段代码,省时省力又能装逼。
好比,你打一个 prop,而后按tab键,就能生成一个带get/set的属性出来。
用好vs的代码片断,是牛逼.Net程序员必备技能。程序员
属性:函数
public int PropertyA { get; set; }
只读属性this
public int PropertyB { get; private set; }
完整属性code
private int fieldC; public int PropertyC { get { return fieldC; } set { fieldC = value; } }
默认构造函数(不带参数)orm
public MyClass() { }
构造函数并自动识别类里面的属性ci
public MyClass(int propertyA, int propertyB) { PropertyA = propertyA; PropertyB = propertyB; }
构造函数并自动识别类里面的fieldget
public MyClass(int fieldC) { this.fieldC = fieldC; }
构造函数并同时识别类里面的field和属性string
public MyClass(int fieldC, int propertyA, int propertyB) { this.fieldC = fieldC; PropertyA = propertyA; PropertyB = propertyB; }
析构函数it
~MyClass() { }
for (int i = 0; i < UPPER; i++) { }
for (int i = length - 1; i >= 0; i--) { }
public object this[int index] { get { /* return the specified index here */ } set { /* set the specified index to value here */ } }
static int main函数io
static int Main(string[] args) { return 0; }
staic void main函数
static void Main(string[] args) { }
System.Windows.Forms.MessageBox.Show("Test");
Console.WriteLine();
try-finally
try { } finally { }
一些其余的代码片断不少人都用过了,不过也许有的人尚未意识到,原来这就是vs的代码片断。
除了系统自带的之外,还能够本身动手添加本身的代码片断,参见:MSDN