我正在尝试在另一个(提供)列表中选择至少有一个城市名称的国家/地区.很抱歉很难解释,请参阅下面的代码:
当我调用GetListOfCountires时,它应该返回NZ和CN.我也想用Linq而不是foreach.
private static List<Country> Countries = new List<Country>();
private static void Main()
{
var city1 = new City {Name = "Auckland"};
var city2 = new City { Name = "Wellington" };
var city3 = new City { Name = "Perth" };
var city4 = new City { Name = "Sydney" };
var city5 = new City { Name = "Beijing" };
var country1 = new Country {Name = "NZ", Cities = new List<City> {city1, city2}};
var country2 = new …Run Code Online (Sandbox Code Playgroud)