部分類和部分方法說明:
部分方法可以是通用的。約束放在定義的部分方法宣告上,并且可以選擇性地在實作方法上重復。實作宣告中的引數和型別引數名稱不必與定義中的相同。
視覺是什么的代碼示例"Constraints are put on the defining partial method declaration, and may optionally be repeated on the implementing one."和"Parameter and type parameter names do not have to be the same in the implementing declaration as in the defining one."?
我不知道上面 2 條陳述句在代碼中的視覺效果如何。
uj5u.com熱心網友回復:
宣言
包括通用約束:
public void Method<TName>(int name) where T : class;
執行
沒有重復的通用約束和不同的引數名稱:
public void Method<TOther>(int other)
{
// ....
}
uj5u.com熱心網友回復:
實作宣告中的引數和型別引數名稱不必與定義中的相同。
public partial class C {
public partial void M<T>(int x);
}
public partial class C {
public partial void M<U>(int y) {
// implementation goes here...
}
}
的兩個宣告M具有不同的型別引數名稱(T和U),以及不同的引數名稱(x和y)。
約束放在定義的部分方法宣告上,并且可以選擇性地在實作方法上重復。
這是不正確的。在C#語言規范說:
宣告中對應的型別引數必須具有相同的約束(型別引數名稱的模數差異)。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/318824.html
上一篇:在Webforms之間發送變數
下一篇:只有陣列的最后一個元素起作用
