Tommy Sin

Tommy Sin

  • NA
  • 19
  • 104.3k

Question about "readonly"

Mar 25 2011 10:08 AM
Hello,

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<string, int> _dictionary = new Dictionary<string, int>();
        static void Main(string[] args)
        {
                _dictionary.Add("a",1);
                _dictionary.Add("b",2);
                _dictionary.Add("c",3);
        }
}


Answers (5)