标签:
2016.4.12
1 public IEnumerator GetEnumerator() 2 { 3 return this; 4 //return this as IEnumerator; 5 } 6 //IEnumerator接口的Current属性 7 public object Current 8 { 9 get 10 { 11 switch (flag) 12 { 13 case 0: 14 return "奥迪"; 15 case 1: 16 return "皇冠"; 17 case 2: 18 return "宝马"; 19 case 3: 20 return "奔驰"; 21 default: 22 return "OH,This is Error!"; 23 } 24 } 25 } 26 //IEnumerator接口的MoveNext方法 27 public bool MoveNext() 28 { 29 flag++; 30 if (flag == 4) 31 return false; 32 return true; 33 } 34 //IEnumerator接口的Reset方法 35 public void Reset() 36 { 37 flag = -1; 38 }
1 //实现IComparable.CompareTo方法 2 //注意无修饰符 3 int IComparable.CompareTo(object obj) 4 { 5 Student s = (Student)obj; 6 if (this.sid > s.sid) 7 return 1; 8 if (this.sid < s.sid) 9 return -1; 10 else 11 return 0; 12 }
1 public delegate string GreetingDelegate(string name);//定义委托 2 public partial class Default : System.Web.UI.Page 3 { 4 //接受一个GreetingDelegate类型的Make方法作为参数 5 public string GreetPeople(string name, GreetingDelegate Make) 6 { 7 return Make(name); 8 } 9 public static string EnglishGreeting(string name) 10 { 11 return "Morning," + name; 12 } 13 public static string ChineseGreeting(string name) 14 { 15 return "早上好," + name; 16 } 17 protected void Page_Load(object sender, EventArgs e) 18 { 19 Response.Write(GreetPeople("Jimmy", EnglishGreeting)+"<br/>"); 20 Response.Write(GreetPeople("李四", ChineseGreeting)+"<br/>"); 21 22 GreetingDelegate gd1, gd2; 23 gd1 = EnglishGreeting; 24 gd2 = ChineseGreeting; 25 Response.Write(GreetPeople("Ondina", gd1) + "<br/>"); 26 Response.Write(GreetPeople("星夜", gd2) + "<br/>"); 27 28 GreetingDelegate gd3; 29 gd3 = EnglishGreeting;//先给委托变量赋值 30 gd3 += ChineseGreeting;// 给此委托变量再绑定一个方法 31 // 将先后调用 EnglishGreeting 与 ChineseGreeting 方法,但只能接收到一个返回值 32 Response.Write(GreetPeople("Fullbuster", gd3) + "<br/>"); 33 Response.Write(gd3("ISIS") + "<br/>"); 34 35 GreetingDelegate gd4 = new GreetingDelegate(EnglishGreeting); 36 gd4 += ChineseGreeting;//绑定语法 37 Response.Write(gd4("Lucy") + "<br/>"); 38 gd4 -= ChineseGreeting;//取消绑定语法 39 Response.Write(gd4("张三") + "<br/>"); 40 } 41 }
总结上述委托编程过程,可以从概念上形成以下几个名词:
1 public interface ImyInterface1 2 { 3 int Add(); 4 } 5 public interface ImyInterface2 6 { 7 int Add(); 8 } 9 public class MyClass : ImyInterface1, ImyInterface2 //继承接口 10 { 11 int ImyInterface1.Add()//显式接口成员实现 12 { 13 int x = 3; 14 int y = 5; 15 return x + y; 16 } 17 18 int ImyInterface2.Add()//显式接口成员实现 19 { 20 int x = 3; 21 int y = 5; 22 int z = 7; 23 return x + y+z; 24 } 25 }
2016.4.13
1 if (!IsPostBack)//是否为第一次响应 2 { 3 StreamReader sr = File.OpenText(Server.MapPath("大神别乱来.txt")); 4 string rt ; 5 while ((rt=sr.ReadLine())!= null) 6 { 7 Response.Write(rt + "<br/>"); 8 } 9 sr.Close(); 10 }
1 Response.Cookies["username"].Expires = DateTime.Now.AddDays(30); 2 Response.Cookies["userpwd"].Expires = DateTime.Now.AddDays(30); 3 Response.Cookies["username"].Value = txtname.Text.Trim(); 4 Response.Cookies["userpwd"].Value = txtpwd.Text.Trim();
1 HttpCookie newCookie = new HttpCookie("userIP"); 2 newCookie.Values.Add("IPaddress", UserIP);//将IP地址存储到Cookie对象中 3 newCookie.Expires = DateTime.Now.AddMonths(1);//设置有效期为一个月
1 Server.MapPath("upload");//MapPath返回与Web服务器上指定虚拟路径相对性的绝对路径 2 Server.MachineName;//获取服务器计算机的名称 3 Server.UrlEncode;//对汉字进行编码 4 Server.UrlDecode;//对汉字进行解码
标签:
原文地址:http://www.cnblogs.com/xingye3327/p/5392782.html