2
我正在重寫一些代碼,同時保持外部接口。我現在需要工作的方法具有以下特徵:Transforming Dictionary <T,U> to Dictionary <T,U.PropertyValue>
public Dictionary<int, string> GetClientIdNames()
這原本直接返回支持字段,驗證它填充它,這樣如果需要的話後。現在有用於存儲更多的數據的要求,所以支持字段如下內容:
private Dictionary<int, Client> _clients;
public struct Client
{
public int ClientId { get; set; }
public string ClientName { get; set; }
public string Password { get; set; }
}
所以,不是簡單地使用foreach
使用Client
的ClientName
屬性,構建從Dictionary<int, Client>
一個Dictionary<int, string>
循環等,我怎麼能在飛行中執行這個轉換?
我會接受你的答案*現在*,但我必須等待10分鐘,顯然。注意,如果我沒有將這個模塊從2.0遷移到3.5,那麼它已經在文件頂部使用了System.Linq,並且問題永遠不會被問到。謝謝! =) – Rob 2010-09-10 09:08:17