我从我的朋友那里得到了一些代码,它在Windows Forms应用程序中运行得很好。
但当我尝试在Xamarin.Forms项目中使用相同的代码时,它显示:
'System.Collections.Generic.List'没有定义ForEach。(可能缺少“using”指令)
我已经:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using Xamarin.Forms;
using System.Reflection;
以下是导致错误的代码:
public Company GetCompanyById(int companyId) {
Company company = new Company();
allContinents
.MyContinents
.Select(x => x.Countries)
.ToList()
.ForEach(countryList => {
countryList.ForEach(country => {
country.Cities.ForEach(city => {
city.Companies.ForEach(com => {
if (com.Id.Equals(companyId))
company = com;
});
});
});
});
return company;
}
为什么它在 Windows.Forms 应用程序中能运行而在此处却无法运行? PS:第一个 ForEach 被蓝色下划线标注。 谢谢。