我只是用这个代码作为例子.假设我有以下Person类.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace dictionaryDisplay
{
class Person
{
public string FirstName { get; private set;}
public string LastName { get; private set; }
public Person(string firstName, string lastName)
{
this.FirstName = firstName;
this.LastName = lastName;
}
public override string ToString()
{
return this.FirstName + " " + this.LastName;
}
}
Run Code Online (Sandbox Code Playgroud)
}
主要计划
static void Main(string[] args)
{
ConcurrentDictionary<int, Person> personColl = new ConcurrentDictionary<int, Person>();
personColl.TryAdd(0, new Person("Dave","Howells"));
personColl.TryAdd(1, new Person("Jastinder","Toor"));
Person outPerson = …Run Code Online (Sandbox Code Playgroud)