我有一個簡單的問題,可能很容易answerd而是大量使用谷歌並沒有彈出一個回答我的問題。所以我很抱歉,如果有正確的解決方案,我沒有看到它。功能的方法調用的參數
如果我有一個像
Object.Add(string text, System.Drawing.Color color);
,它是將一些文本的一些對象與指定顏色的方法調用,我想動態改變顏色,那麼我可以鍵入某事。像
Object.Add("I'm a string", SomeBool ? Color.Red : Color.Green);
這是非常有幫助的,但只要我想比較不僅僅是兩種情況,就會失敗。
我正在尋找的是類似的信息(僞)
Object.Add("I'm another string", new delegate (Sytem.Drawing.Color)
{
if (tristate == state.state1)
{
return Color.Blue;
}
else if (tristate == state2)
{
return Color.Green;
}
// ...
});
但不管如何我想它會拋出一個編譯器錯誤。
我嘗試瞭如何將一個函數作爲方法參數,但我會發現,很多像
public void SomeFunction(Func<string, int> somefunction)
{
//...
}
這是不是我的問題很多谷歌的。
謝謝:)
非常好的解決方案。喜歡它 :) – AllDayPiano