Expand Minimize
This topic has not yet been rated - Rate this topic

Compiler Error CS1604

Cannot assign to 'variable' because it is read-only

An assignment was made to a read-only variable.

The following sample generates CS1604:

// CS1604.cs
class NoWrite
{
   public static void Main()
   {
      int [] a = {1,2,3};

      foreach(int k in a)
      {
         k = k + 1;   // CS1604, k is read-only
         System.Console.WriteLine(k);
      }
   }
}
Did you find this helpful?
(1500 characters remaining)
© 2013 Microsoft. All rights reserved.