我有一个Array
ofPerson
对象,我想将它转换为一个ConcurrentDictionary
. Array
有将 a 转换为 a的扩展方法Dictionary
。是否有任何将 a 转换Array
为 a 的扩展方法ConcurrentDictionary
?
public class Person
{
public Person(string name, int age)
{
Name =name;
Age = age;
}
public string Name { get; set; }
public int Age { get; set; }
}
Dictionary<int, Person> PersonDictionary = new Dictionary<int, Person>();
Person[] PersonArray = new Person[]
{
new Person("AAA", 30),
new Person("BBB", 25),
new Person("CCC",2),
new Person("DDD", 1)
};
PersonDictionary = PersonArray.ToDictionary(person => person.Age);
任何类似的扩展方法/ lambda 表达式用于将 a 转换Array
为 a ConcurrentDictionary
?