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