I am just wondering how I could add elements to the Dictionary below even if it is declared as readonly.
Are we not supposed to be able to modify the dictionary if it is declared as readonly?
Thanks.
class program
{
private static readonly Dictionary
static void Main(string[] args)
{
_dictionary.Add("a",1);
_dictionary.Add("b",2);
_dictionary.Add("c",3);
}
}

VulpesRank #55 · 29.2K reputationPosted Mar 25, 2011, 6:11 AM EDT
What you can't do is to assign a different Dictionary object to it which can only be done from the constructor or 'in situ'.
Tommy Sin19 reputationPosted Mar 25, 2011, 6:17 AM EDT
Thanks for your explanation.
By the way, what do you mean by 'in situ'?
Thanks
VulpesRank #55 · 29.2K reputationPosted Mar 25, 2011, 6:22 AM EDT
So, in your code, you've assigned a new Dictionary object to the readonly field _dictionary when you've declared it or 'in situ'.
As it's a private static field, you can add elements to it (or remove elements from it) from any instance or static method in the program class but you can't change the actual Dictionary object itself.
Sam HobbsRank #107 · 20.5K reputationPosted Mar 25, 2011, 8:43 PM EDT
VulpesRank #55 · 29.2K reputationPosted Mar 26, 2011, 3:47 AM EDT
It's just a Latin phrase which means "in the original position".