摘要: public delegate void Del(string message);public static void DelegateMethod(string message){ System.Console.WriteLine(message);}// Instantiate the delegate.Del handler = DelegateMethod;// Call the dele... 阅读全文
posted @ 2009-09-23 16:01 greencolor 阅读(181) 评论(0) 推荐(0) 编辑
摘要: class SampleCollection<T>{ private T[] arr = new T[100]; public T this[int i] { get { return arr[i]; } set { arr[i] = value; } }}// This class shows how client code uses the indexerclass Program... 阅读全文
posted @ 2009-09-23 15:48 greencolor 阅读(133) 评论(0) 推荐(0) 编辑
摘要: public class DaysOfTheWeek : System.Collections.IEnumerable{ string[] m_Days = { "Sun", "Mon", "Tue", "Wed", "Thr", "Fri", "Sat" }; public System.Collections.IEnumerator GetEnumerator() { for (int i =... 阅读全文
posted @ 2009-09-23 15:28 greencolor 阅读(177) 评论(0) 推荐(0) 编辑
摘要: int this[int index] { get; set; }===========public class Int16Collection : CollectionBase{ public Int16 this[int index] { get { return ((Int16)List[index]); } set { List[index] = value; } }..... 阅读全文
posted @ 2009-09-23 13:08 greencolor 阅读(134) 评论(0) 推荐(0) 编辑
摘要: public static class StringExtensions{ public static string HeiHei(this string str) { return str + "嘿嘿"; }}HeiHei 是静态的;HeiHei 参数的第一个关键词是 this;HeiHei 参数的第二个关键词是 string,表示对string 的扩展; 阅读全文
posted @ 2009-09-23 12:50 greencolor 阅读(158) 评论(0) 推荐(0) 编辑
摘要: var doc = new { Title = "标题", Content = "内容" };Response.Write(doc.Title);int id = 1;int value = 2;var obj = new { id, value };Response.Write(obj.value.ToString()); 阅读全文
posted @ 2009-09-23 12:45 greencolor 阅读(152) 评论(0) 推荐(0) 编辑
摘要: System.Collections.Generic.List<string> authors = new System.Collections.Generic.List<string>();authors.Add("作者一");authors.Add("作者二");authors.Add("作者三");--------------------------------Lis... 阅读全文
posted @ 2009-09-23 12:44 greencolor 阅读(139) 评论(0) 推荐(0) 编辑
摘要: 抽象方法不做什么事情,所以不需要大括号,直接加引号结束即可。在派生类中,用 override 来实现这个抽象方法。抽象的类不能被实例化,所以不能用 new 来产生实例。如果方法是抽象的,则类必须是抽象的。派生类必须实现基类中的所有抽象方法,如果它不能做到,那么它也应该是个抽象类。抽象类不能是密封的。(关于密封:如果我们不想让一个类被继承,可以使用 sealed 关键字来确保它不会被继承。)publ... 阅读全文
posted @ 2009-09-23 11:56 greencolor 阅读(185) 评论(0) 推荐(0) 编辑
摘要: 不能重写非虚方法或静态方法。重写的基方法必须是 virtual、abstract 或 override 。virtual 用在基类中,指定一个虚方法(属性),表示这个方法(属性)可以重写。override 用在派生类中,表示对基类虚方法(属性)的重写。public class BaseClass{ public virtual string GetString() { return "这是一个虚方... 阅读全文
posted @ 2009-09-23 11:51 greencolor 阅读(208) 评论(0) 推荐(0) 编辑
摘要: Each class have following methods:EqualsGetHashCodeDisposalGetTypeToStringThese methods can be modified through the override methods.For examplepublic override bool Equals(object cmp)public virtual vo... 阅读全文
posted @ 2009-09-23 11:46 greencolor 阅读(151) 评论(0) 推荐(0) 编辑