C# tips

1. .NET 3.0 introduces a new concept of Auto-implemented properties. In short you can do things like: public class MyClass { public int X { get; set; } } Instead of: public class MyClass { private int _x; public int X { get { return _x; } set { _x = value; } } } 2. C# offers the ability to make things like ‘int’ a nullable type. int? x = null; if (x == null || !x.HasValue) { x = 5; } Console.WriteLine(x.ToString()); 3. Aliases make it easier for you to shortcut to your most common called classes. using c = System.Console; using myMethod = System.Reflection.MethodBase; class Program { static void Main(string[] args) { c.WriteLine(myMethod.GetCurrentMethod().Name); } } 4. A favorite shortcut of mine is ‘Ctrl+R+M’ lets you turn any segment of highlighted code into a new method. 5. .NET 4 has a new feature for keeping track of parameters that you may be passing in, you can now prepend values / variables with labels: static void Main(string[] args) { File.Copy(sourceFileName: "Myfile.txt", destFileName: "dest.txt"); }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值