【发布时间】:2019-12-27 16:46:58
【问题描述】:
我想使用来自另一个类的动态数字 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);
}
【问题讨论】:
-
您使用什么语言?有些语言可以让您向现有列表添加范围,例如 C# 中的 List.AddRange。
-
我正在为此使用 C#
-
然后你可以使用ArrayList.AddRange()。在此处查看文档:docs.microsoft.com/en-us/dotnet/api/…