我想使用来自另一个类的动态数字ob对象作为我的“公司”类的属性。为此,我想使用ArrayList进行处理。以下哪种方法可行或更好?还是有其他需要改进的想法?
public ArrayList IndustryList = new ArrayList();
//Method return an array of Class IndustryID
IndustryID[] industry = IndustryID.get_IndustryID();
//Did both options work or which is better?
//Option1
IndustryList.Add(industry);
//Option2
foreach (IndustryID industry_obj in industry)
{
Industrylist.Add(industry_obj);
}
答案 0 :(得分:0)
首先从List<IndustryID>
返回此类型IndustryID.get_IndustryID();
然后;
public class Company{
public List<IndustryID> Industries;
Company(List<IndustryID> industries){
Industries = industries;
}
}
用法:
Company obj = new Company(IndustryID.get_IndustryID());
foreach(var one in obj.Industries){
Console.WriteLine(one.Name);
}