public class PeopleCollection : IEnumerable
{
private Dictionary<string, Person> listPeople = new Dictionary<string, Person>();
// This indexer returns a person based on a string index.
public Person this[string name]
{
get {
return (Person)listPeople[name]; // **Is this cast necessary?**
}
set {
listPeople[name] = value;
}
}
..
}
問題:我們是否應該將返回值從listPeople[name]
轉換爲Person
?C# - 我們應該投入索引器方法
謝謝
它已在字典聲明中明確地轉換爲Person。 – canon 2011-05-17 16:23:55