是否可以做类似的事情:
using MyCustomDto = (flag == "library1") ? MyLibrary1.Dtos.MyDto1 : MyLibrary2.Dtos.MyDto2;
Run Code Online (Sandbox Code Playgroud)
我不能为此找到正确的语法。因此,根据appsettings.config中的标志,我想从特定的库加载Dto,它们具有不同的名称空间,如您所见,这将是using指令块的一部分,在该块中,您通常会看到以下语句:
using System.Collections.Generic;
Run Code Online (Sandbox Code Playgroud) 我如何从List<ComplexObject>a 获得List<string>,假设ComplexObject有两个属性:类型为string的prop1和类型为int的prop2.我有兴趣提取一个List<string>(prop1列表).
举个例子,也许它更清楚.
想象一下,你有List<Country>Country是具有Id和Name的复杂对象.我有兴趣从countryList中提取一个名称列表,其中包含所有名称.
我知道我可以这样做:
List<string> nameList = new List<string>();
foreach (var country in countryList)
{
nameList.Add(country.Name);
}
Run Code Online (Sandbox Code Playgroud)
...但我想知道是否有更简单快捷的方法从countryList中提取nameList.也许与lambda或其他东西.
并且该字符串列表是否可以轻松转换为DataTable?
谢谢.