I want to use a collection initializer for the next bit of code:
public Dictionary<int, string> GetNames()
{
Dictionary<int, string> names = new Dictionary<int, string>();
names.Add(1, "Adam");
names.Add(2, "Bart");
names.Add(3, "Charlie");
return names;
}
So typically it should be something like:
return new Dictionary<int, string>
{
1, "Adam",
2, "Bart"
...
But what is the correct syntax for this?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…