下面的程式碼範例示範如何?自訂集合的 IEnumerable 介面。在此樣本中,沒有顯式調用但實現了 GetEnumerator,以便支援使用 foreach(在 Visual Basic 中為 for each)。此程式碼範例摘自 IEnumerable 介面的一個更大的樣本。view plaincopy to clipboardprint?public class People : IEnumerable { private Person[] _people; p
PDF 瀏覽:http://www.tracefact.net/document/generics-in-csharp.pdf源碼下載:http://www.tracefact.net/SourceCode/Generics-In-CSharp.rar出 處:http://www.ondotnet.com/pub/a/dotnet/2004/05/17/liberty.htmlC# 理解泛型術語表generics:泛型type-safe:型別安全collection:
If want filter out a price greater than $10 ,in the products. we need to loop around,testing each element and printing it out where appropriate. Looping ,testing,printing out C#1.1static void Main() { ArrayList products =
我眼中的C# 3.0 Written by Allen Lee 緣起 每次有新技術發布時,我們總能感受到兩種截然不同的情緒:一種是恐懼和抵抗,伴隨著這種情緒的還有諸如"C# 2.0用的挺好的,為什麼要在C# 3.0搞到那麼複雜?"或者"我還在使用C# 1.0呢?"等言辭;另一種則是興奮和擁抱,伴隨著這種情緒的還有諸如"原來這個問題在C# 3.0裡可以這麼簡單!"等言辭。 最近我在公司內部做一個LINQ的系列講座,在我為其中C#
原來還準備自己寫演算法,並研究農曆規則。發現那太難和麻煩了,光是農曆的推算那就我等專門研究曆法的人一下搞懂的。後來發現。NET類庫也提供一些基礎的農曆類System.Globalization.ChineseLunisolarCalendar。我改裝了一下如DateTime時間形式。代碼如下。實現了 西曆農曆轉換的功能。但是只能算到1900~2100年之間的。基本夠日常使用了。原始碼如下。 using System; using
event 關鍵字用於在發行者類中聲明事件。下面的樣本示範如何聲明和引發將 EventHandler 用作基礎委託類型的事件。public class Publisher{ // Declare the delegate (if using non-generic pattern). public delegate void SampleEventHandler(object sender, SampleEventArgs e); // Declare the event.
C#中提供了三種類型的計時器:1、基於 Windows 的標準計時器(System.Windows.Forms.Timer)2、基於伺服器的計時器(System.Timers.Timer)3、線程計時器(System.Threading.Timer)下面我就通過一些小實驗來具體分析三種計時器使用上面的異同點,特別是和線程有關的部分。實驗例子:一、基於 Windows 的標準計時器(System.Windows.Forms.Timer)首先注意一點就是:Windows