我正在设置一个看起来像这样的项目列表。
List<BankInfo> all_branches = new List<BankInfo>();
Equipment.set_slot = "Mail";
all_branches.Add(new BankInfo
{
name = "West Bank",
city = "San Francisco",
owner = new Person { name = "Jeff Bridges", age = 55 }
});
all_branches.Add(new BankInfo
{
name = "East Bank",
city = "Concord",
owner = new Person { name = "Upton Sinclair", age = 102 }
});
写数百个这样的东西非常麻烦,如果我必须这样写,我会更喜欢
--
Name: West Bank
City: San Francisco
Owner: Jeff Bridges, 55
--
Name: East Bank
City: Concord
Owner: Upton Sinclair, 102
有没有办法做这样的事情?
至少有什么方法(在 c# 中)可以使像 $ITEM 这样的符号变成 all_branches.Add(new BankInfo { 所以我可以只做 $ITEM (就像 C++ 中的宏)?