我有以下空字典
Dictionary<Guid, string> appTypeMap = new Dictionary<Guid, string>();
和以下列表:
List<ApplicationType> allApplicationTypes = _applicationTypeService.GetAll()
应用类型描述如下:
public class ApplicationType
{
public Guid id {get; set;}
public String name {get; set;}
}
我想使用 LINQ 填充字典。
我怎么做?
谢谢。
最佳答案
appTypeMap = allApplicationTypes.ToDictionary(x => x.id, x => x.name);
但是,它会创建一个新字典,而不是填充您的字典。
关于c# - 使用 linq 填充字典,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15324282/