我正在設置一個類似這樣的項目列表。基於文本文件定義項目(C#)
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#),以讓這個像$項的符號變成all_branches.Add(新BankInfo {所以我只能做$項目(如在C++)宏?
如何從文本或XML文件中讀取所有這些數據,然後編寫一個函數來完成所有這些操作。 – Pankaj