using System;namespace DelegateSample{ public delegate void PrintCallback(int number); public class Printer{ //委託定義 private PrintCallback _print; //委託將要依附的屬性 public PrintCallback PrintCallback{ get{return
泛型最大的4個好處:1,效能 分析下面的例子 ArrayList的Add()方法定義為需要把一個對象作為參數,所以要裝箱一個整數類型。在讀取ArrayList中的值時,要進行拆箱,把對象轉換為整數類型。 裝箱和拆箱操作容易使用,但是效能損失比較大,迭代許多項時尤其如此。 CODE 1:ArrayList list = new ArrayList();list.Add(44); // boxing - covert a value type to a reference
Java介面中可以定義變數成員。如:interface abc{ int num=1;}可以編譯通過。而C#的介面中只能寫函數原型。任何欄位也不能包括。不管是否常量,靜態變數。我認為還是C#更規範些啊。介面中本來是不應該有任何實現的。如果需要用到常量,可以建立抽象類別,抽象類別實現這個介面,這樣在抽象類別中定義需要的欄位就可以了。P.S.一直不明白的還有為什麼Java中的Protected存取修飾詞可以被本包中非子類訪問。有知道的朋友請一定告訴我,謝謝啦!
Finalize方法常用於回收非託管資源,以防止資源流失在較少的情況下它也會被用於託管資源1.建構函式中如果拋出異常, 那麼只有Finalize方法才會被執行,在這裡可以回收一些已經分配的資源(Dispose不會被執行!!!)當然:Finalize方法的執行時間還是下一次GC的時候(依然不確定時間)如果不實現該方法將會造成資源流失以下代碼示範了在這種情況代碼Code highlighting produced by Actipro CodeHighlighter (freeware)http:/
At the age of .net, all the benefits c++ could have is deduced to the efficiency. It gives you way too much control over the working of the native layer infrastructure. While the cpu is growing faster and faster, memory is increasing day by day,