Bic*_*ick 36 c# linq dictionary list
我有以下空字典
Dictionary<Guid, string> appTypeMap = new Dictionary<Guid, string>();
Run Code Online (Sandbox Code Playgroud)
以下列表:
List<ApplicationType> allApplicationTypes = _applicationTypeService.GetAll()
Run Code Online (Sandbox Code Playgroud)
应用程序类型描述如下:
public class ApplicationType
{
public Guid id {get; set;}
public String name {get; set;}
}
Run Code Online (Sandbox Code Playgroud)
我想使用LINQ填充字典.
我怎么做?谢谢.
Mar*_*zek 79
appTypeMap = allApplicationTypes.ToDictionary(x => x.id, x => x.name);
Run Code Online (Sandbox Code Playgroud)
但是,它会创建一个新词典,而不是填写你的词典.