设置了两个get set变量,name,cost
ArrayList里创建一个新的元素集合。
请问如何能在 Arraylist 里添加name ,cost这两个变量然后现实出来?
ArrayLIst.Add("name{0} cost{1}",name,cost);
貌似这样添加不进去呀,求帮助。
我是个新手。。可能表达上稍微有点问题,希望见谅~
ArrayList里创建一个新的元素集合。
请问如何能在 Arraylist 里添加name ,cost这两个变量然后现实出来?
ArrayLIst.Add("name{0} cost{1}",name,cost);
貌似这样添加不进去呀,求帮助。
我是个新手。。可能表达上稍微有点问题,希望见谅~
ArrayLIst.Add(cost)就可以啊
显示的话。ArrayLIst[0]代表name的值,ArrayLIst[1]代表cost的值,根据你的数据类型,可能还需要转换一下数据类型,建议你使用List<string> nameList用来存name,list<string>constList用来存cost。
namespace AAA
{
public class Product
{
public string Name {get;set;}
public decimal Cost {get;set;}
} public class Test1
{
static void Main(string[] args)
{
ArrayList al = new ArrayList();
al.Add(new Product(){Name="人参果",Cost="8888.88"});
al.Add(new Product(){Name="XXX",Cost="6666.66"});
//其他操作
}
}
}
namespace AAA
{
public class Product
{
public string Name {get;set;}
public decimal Cost {get;set;}
} public class Test1
{
static void Main(string[] args)
{
Dictionary<string, int> a = new ....();
a.Add("name", 1);
foreach(int val in a.Values)
{
// Console.
}
int val = a["name"];
}
}
}