我有一个班级国家和另一班CountryBO。 从主类,我即时创建CountryBO,并在CountryBO的对象上,我打电话给一个方法定义在 CoountryBO类称为createCountry。 在这种方法中,我即时创建Country类的对象并设置一些变量,同时返回新创建的对象的引用。如何在C#中的列表中存储对象的引用?
public Country createCountry(String data)
{
string [] countryDetail = data.Split(',');
Country myCountry = new Country();
myCountry._countryCode=countryDetail[2];
myCountry._isdCode=countryDetail[1];
myCountry._name=countryDetail[0];
return myCountry;
}
现在在调用主类,我想创建创建国家一流帽子的所有对象的列表。 但我无法做到。
CountryBO myCountryBO = new CountryBO();
Country[] countryList = new Country[];
countryList = myCountryBO.createCountry(countryDetails);
countryCount +=1;
你可以发布两个类的定义吗?你还遇到什么错误? –
改为使用'List',那么你可以使用'list.Add(myCountryBO.createCountry)'。数组不像功能丰富的通用列表。 –
Charleh
问题不明确,是否有可能countryCount需要静态?我不确定你想要完成什么。 – Protium