我不确定何时应该使用匿名类型而不是局部变量在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