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 =
摘要 在這個代碼片斷中,Joseph 測試了一個使用 C# 反射來自動實現屬性時,發生了一個意想不到行為的方案。之後提供了該方案的分步說明,他提供了樣本項目最終輸出的、相關的 C# 完整代碼、Visual Studio 2008的項目下載。 by Joseph Chahine Code Listing 1: Employee.csCode highlighting produced by Actipro CodeHighlighter
今天看《Pro Net 2.0 Windows Forms And Custom Cortrols In C#》時看到枚舉一節,發現了在一個枚舉裡面需要合并多個值,看到了用到了”|”運算子,原來沒怎麼注意,今天想了一下為什麼用”|”呢? 在MSDN裡面看到了這樣一句話:“用2的冪(即 1、2、4、8 等)定義枚舉常量。這意味著組合的枚舉常量中的各個標誌都不重疊。” 於是寫了一個例子: [FlagsAttribute] enum Colors_1
委託的匿名方法 這幾天在看微軟的MVP設計模式的例子的時候,偶然發現它將DropDownList的SelectIndexChange事件委託直接執行個體化成一個不帶任何參數匿名方法。具體例子如下: CodeCode highlighting produced by Actipro CodeHighlighter
建構函式是和類名相同的類的一個方法,如果沒有顯式的聲明,在系統會在編譯的時候,自動產生一個不帶參數的,不執行任何動作的建構函式。 但如果顯式的聲明了建構函式,系統就不會自動產生了。如果聲明的建構函式是有參數的建構函式,我們在執行個體化類的時候,就必須以該建構函式而執行個體化類。看下面的代碼:CodeCode highlighting produced by Actipro CodeHighlighter
①string ax=string.Empty; 注:不要使用: string ax=""; I don't konw why.But it's Microsoft's convention.判斷ax是否為空白:ax.Length==0 > ax==string.Empty Info : "To test for empty strings, check if String.Length is equal to