我不確定何時應該使用匿名類型而不是局部變量在C#中。匿名類型VS局部變量,何時應該使用?
我:
string fullMessage // This is the full message including sender and recipient names
string sender = GetMessagePart(fullMessage, "from");
string recipient = GetMessagePart(fullMessage, "to");
//do some stuff and deliver the message
我應該使用:
var msg = new {
sender = GetMessagePart(fullMessage, "from")
recipient = GetMessagePart(fullMessage, "to")
};
呢?
[應該如何在C#中使用匿名類型](http://stackoverflow.com/questions/48668/how-should-anonymous-types-be-used-in-c) – nawfal 2014-07-15 15:28:42