Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
c#窗体中arrayList的{get;set;}_C#_Arrays_Arraylist - Fatal编程技术网

c#窗体中arrayList的{get;set;}

c#窗体中arrayList的{get;set;},c#,arrays,arraylist,C#,Arrays,Arraylist,对于arraylist是否有使用set和get的解决方案? 我想把我所有的ArrayList放在一个类中,但是我需要它们填充一个二维数组来使用它们。(1个列表=1列) 我想把这个 ArrayList listanume = new ArrayList(); 在这方面: class Beneficiar {} 然后用它来填充二维数组,比如 listanume -> a[i,0] 我真的不知道该怎么说才对,但这就是我的想法…你应该这样做 class Program {

对于arraylist是否有使用set和get的解决方案?
我想把我所有的ArrayList放在一个类中,但是我需要它们填充一个二维数组来使用它们。(1个列表=1列)

我想把这个

ArrayList listanume = new ArrayList();  
在这方面:

class Beneficiar
{}  
然后用它来填充二维数组,比如

listanume -> a[i,0]

我真的不知道该怎么说才对,但这就是我的想法…

你应该这样做

 class Program
{
    public static void Main(string[] args)
    {
        List<Account> accounts = new List<Account>();
        Account a1 = new Account { Name = "Peter", Password = "lalala", Mail = "mail@yahoo.com", 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; }
}

出于各种原因,这听起来是个坏主意。现在为什么要使用
ArrayList
?为什么把他们都放在一个班里?这些数据实际上代表什么?您试图用这些数据结构实现什么?填充2D数组与属性getter和setter有什么关系?这是一种帐户表单,我选择可以随时添加+1的数组。我需要一个2D数组,因为我认为它更容易通过名称、销售或任何写满它的标准进行搜索。与其问你明显错误的解决方案,不如试着问你需要解决的问题。
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);