上一页 1 2 3 4 5 6 7 ··· 20 下一页

2013年11月29日

事件

摘要: /*事件定义事件需要用委托类型的去声明一个事件。*/using System;namespace Frank{ public class Test { public delegate string Get(string x);//自定义委托 //简写模式的事件 public event Get NewEvent;//自从有了EventHandler泛型委托后就在也不需要自己定义委托了。它有两个参数,第一个是调用者,第二个是T类型。还定义了约束。 //完整模式的事件定义,类似于属性和字段。编译器自动的添加的。 /* public event Get NewEvent2 { ... 阅读全文

posted @ 2013-11-29 16:54 wp456 阅读(206) 评论(0) 推荐(0)

匿名方法和Lambda表达式的使用

摘要: /*匿名方法和Lambda表达式的使用*/using System;namespace Frank{ public class Test { public static void Main(string[] args) { string mid = ", middle part,"; Func anonDel = delegate(string param)//创建匿名方法交给委托 { param += mid; param += " and this was added to the string."; return param... 阅读全文

posted @ 2013-11-29 14:07 wp456 阅读(165) 评论(0) 推荐(0)

2013年11月28日

多播委托

摘要: /*多播委托*/using System;namespace Frank{ public class Test { public static void Main(string[] args) { Action operations = MathOperations.MultiplyByTwo; operations += MathOperations.Square; ProcessAndDisplayNumber(operations,20.00);//一次执行多个方法,如果一个方法抛出了异常,那么后面的方法就不会被执行。 //为了避免方法抛... 阅读全文

posted @ 2013-11-28 17:05 wp456 阅读(175) 评论(0) 推荐(0)

委托练习一

摘要: /*委托*/using System;namespace Frank{ public class Test { private delegate string GetAString();//定义委托 private delegate double DoubleOp(double x);//定义第二个委托 public static void Main(string[] args) { GetAString str = new GetAString(1.ToString); GetAString str2 = 1.ToString;//自动类型推断 ... 阅读全文

posted @ 2013-11-28 14:42 wp456 阅读(140) 评论(0) 推荐(0)

params、explicit、可选参数和implicit的使用

摘要: /*params、explicit、可选参数和implicit的使用explicit 显示的implicit 隐士的params 可变参数必须是参数列表最后一个*/using System;namespace Frank{ public class Test { public int Count{get;set;} public static void Main(string[] args) { Test t = new Test(); t.Count = 10; Test2 t2 = new Test2(); t2.Count = 20; ... 阅读全文

posted @ 2013-11-28 10:46 wp456 阅读(227) 评论(0) 推荐(0)

2013年11月27日

运算符的重载

摘要: /*运算符的重载运算必须是public和static的。公共的静态实例,而不是特定的。*/using System;namespace Frank{ public class Test { public static void Main(string[] args) { Test2 t1 = new Test2(); t1.Count = 1; Test2 t2 = new Test2(); t2.Count = 4; System.Console.WriteLine((t1+t2).Count);//输出5 System.Consol... 阅读全文

posted @ 2013-11-27 16:55 wp456 阅读(159) 评论(0) 推荐(0)

相等性的理解

摘要: /*相等性的理解*/using System;namespace Frank{ public class Test { public static void Main(string[] args) { /* object里面有个Equals方法和==结果一样 微软为基础结构类型和string类型重载了==运算符,所以使用==的时候比较是内容,不在是引用地址。如果自己定义类或者结果最好重写Equals和重载==运算符,这样子才不会存在比较引用地址。 object里面还有一些其他比较方法。 */ } }} 阅读全文

posted @ 2013-11-27 16:15 wp456 阅读(148) 评论(0) 推荐(0)

类型转换

摘要: /*类型转换*/using System;namespace Frank{ public class Test { public static void Main(string[] args) { double d = 1.6; int i = (int)d;//丢失小数点后面的 System.Console.WriteLine(i);//1 double us1 = 65.1; char c1 = (char)us1; System.Console.WriteLine(c1);//A } }} 阅读全文

posted @ 2013-11-27 16:08 wp456 阅读(101) 评论(0) 推荐(0)

运算符的介绍

摘要: /*运算符的介绍*/using System;namespace Frank{ public class Test { public static void Main(string[] args) { //检查运算 byte b = 255; checked //执行安全检查 { //b++;//异常 } unchecked//不执行安全检查,默认方式 { b++;//不异常,但是溢出会得到0 } System.Console.WriteLine(b); //is运算 int i = 10; if(i... 阅读全文

posted @ 2013-11-27 15:45 wp456 阅读(166) 评论(0) 推荐(0)

元组

摘要: /*元组元组可通过.net框架用于所有的.net语言.net 4定义了8个泛型Tuple类和一个静态的Tuple类,它们用作元组的工厂。*/using System;namespace Frank{ public class Test { public static void Main(string[] args) { Tuple result = Divide(2,5); System.Console.WriteLine(string.Format("{0}----{1}",result.Item1,result.Item2)); } ... 阅读全文

posted @ 2013-11-27 14:41 wp456 阅读(158) 评论(0) 推荐(0)

上一页 1 2 3 4 5 6 7 ··· 20 下一页

导航