你應該做這樣的事情
class Program
{
public static void Main(string[] args)
{
List<Account> accounts = new List<Account>();
Account a1 = new Account { Name = "Peter", Password = "lalala", Mail = "[email protected]", TotalSold = 100M };
accounts.Add(a1);
}
}
public class Account
{
public string Name { get; set; }
public string Password { get; set; }
public string Mail { get; set; }
public decimal TotalSold { get; set; }
}
要有些外地訪問任何帳戶,你可以做到這一點
string searchNameString = "Peter";
var foundAccount = accounts.FirstOrDefault(x => x.Name == searchNameString);
if (foundAccount != null)
{
//Code which uses found account
}
//Here you will get all accounts with total sold > 1000. You can then iterate over them with for or foreach
var foundAccountsByTotalSold = accounts.Where(x => x.TotalSold > 1000);
來源
2017-04-15 09:24:33
Evg
這聽起來像是出於各種原因一個壞主意。爲什麼現在使用'ArrayList'?爲什麼把他們全部放在一個班級?這些數據實際上代表什麼以及你想用這種數據結構實現什麼?填充二維數組有哪些與屬性獲取器和設置器有關? – jmcilhinney
這是一個賬戶表單,我選擇數組可以隨時添加+1。我需要一個二維數組,因爲我認爲這是更容易搜索的名稱,出售或任何標準 –
這[XYPropblem](http://meta.stackexchange.com/questions/66377/what-is-the-xy-問題)寫在它上面。不要詢問你明顯錯誤的解決方案,而應詢問你需要解決的問題。 –