fork download
  1. using System;
  2.  
  3. public class Test
  4. {
  5. public readonly string field = "foo";
  6.  
  7. public static void Main()
  8. {
  9. var t = new Test();
  10. t.field = "bar";
  11. }
  12. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cs(10,11): error CS0191: A readonly field `Test.field' cannot be assigned to (except in a constructor or a variable initializer)
Compilation failed: 1 error(s), 0 warnings
stdout
Standard output is empty