I need to create a class that combines two dictionaries together so that their values ββcan be obtained by key from the string int or .
Properties seems to be the best approach here, but is there a difference between the two implementations?
public class Atlas<TValue> { private Dictionary<int, TValue> _byIndex; private Dictionary<string, TValue> _byName; public Dictionary<int, TValue> ByIndex { get { return _byIndex; } } public Dictionary<string, TValue> ByName { get { return _byName; } } }
and
public class Atlas<TValue> { public Dictionary<int, TValue> ByIndex { get; private set; } public Dictionary<string, TValue> ByName { get; private set; } }
In any case, the dictionary object is immutable, and the elements can be freely changed, which is what I want. However, an attempt to modify the dictionary object will either result in ~ cannot be assigned to -- it is read only , or ~ cannot be used in this context because the set accessor is inaccessible . I understand that the compiler will confuse my auto properties into something similar to the top block of code anyway ...
Actually, what compiler error is occurring?
source share