- Jun 14 Thu 2012 18:29
[C#] 實現Singleton的方法比較
- Jun 12 Tue 2012 15:57
[C#] "Where" of LINQ (three methods)
- Jun 12 Tue 2012 00:27
[ASP.NET] Asp.net datasource 綁定資料實作
http://www.csharpwin.net/ddwstp/net/csharp/5723dr4312.shtml
簡單明瞭不囉嗦。這段威威..~"~
=====重點整理一下關於綁定自己設定的DataType方法====
<4>绑定对象集合,IList等。这个很是有用,在我们进行数据查询的时候,经常从数据库取出数据,为了方便操作,需要封装成对象,但是有的时候需要将这些对象以列表的形式显示出来,一种解决方案:对象转换为DataTable,另一种就是直接调用数据库。这两种方案,并不是很理想。而这里直接将对象集合直接绑定到数据显示控件,给我指明一条出路。其实,在PetShop4.0就是利用这一点,绑定ICollection或者IList。简单明了。
- Apr 15 Sun 2012 16:38
[C#] "Where" of LINQ (three methods)
// Main function
class MainFunc { static void Main(string[] args) { string[] animals = new string[] { "Koala", "Spider", "Elephant" }; wherepractice prac = new wherepractice(); // get animals of StartName is "S" prac.detailWhere(animals); // get amimals of StartName is "E" prac.lambdaWhere(animals); // as above result, but different implement. prac.delegateImpleWhere(animals); Console.ReadLine(); return; } }
// subClass
public void detailWhere(string[] animals) { var q = from a in animals where a.StartsWith("S") select a; foreach (string s in q) { printString(s); } } public void lambdaWhere(string[] animals) { var q = animals.Where(a => a.StartsWith("E")); foreach (string s in q) { printString(s); } } public void delegateImpleWhere(string[] animals) { // To utilize "delegate" to implement lambda expression "Where". var q = animals.Where( delegate(string a){return a.StartsWith("E");} ); foreach (string s in q) { printString(s); } }
- Apr 15 Sun 2012 16:30
[C#] goto statement
This is a simple sample for Exit statement.
static void Main(string[] args) { Program.correctGoto(); Program.GotoInfiniteLoop(); Program.falseGoto(); } //This is a correct Goto statement method. static public void correctGoto() { for (int i = 0; i < 100; i++) { Console.WriteLine("{0}", i); if (i == 5) { goto Exit; } } Exit: Console.WriteLine("Exit"); } //If you put Exit tag before goto statement, it will cause infinite loop.p> static public void GotoInfiniteLoop() { Exit: Console.WriteLine("Exit"); for (int i = 0; i < 100; i++) { Console.WriteLine("{0}", i); if (i == 7) { goto Exit; } } } //It's a wrong method to use exit statement. static public void falseGoto() { for (int i = 0; i < 100; i++) { Console.WriteLine("{0}", i); if (i == 7) { Exit: Console.WriteLine("Exit"); } // this method can't jump from external into internal. goto Exit; } }