private void LoadList (object [] items
{
for (int i =
l
}這個函數從一個可為任何對象的數組中加載ListBox
private void LoadList (ICollection items
{
foreach (object o in items)
l
}
ICollection被數組和所有System
因為屬性已經成為語言本身的元素
最後
這裡還有維護方面的因素應當注意
private int TheMonth =
[XmlAttribute (
public int Month
{
get {
return TheMonth;
}
set {
TheMonth = value;
}
}
簡單通過屬性就可以使你的所有數據元素私有化
當你生成一個實現producer idiom類的時候
下面的類處理鍵盤輸入並把它傳給所有的registered listeners
public class KeyboardProcessor
{
private OnGetLine theFunc = null;
public OnGetLine OnGetLineCallback {
get {
return theFunc;
}
set {
theFunc = value;
}
}
public void Run (){
// Read input
// If there is any listeners
string s;
do {
s = Console
if (s
break;
if (theFunc != null){
System
foreach (OnGetLine f in funcs) {
try {
f (s);
} catch (Exception e) {
Console
(
}
}
}
} while (true);
}
任何數目的listeners都可注冊到producer
C#中對於一些變量聲明加入了initializer的概念
所以
From:http://tw.wingwit.com/Article/program/net/201311/13589.html