Sponsored Ad

Friday, February 25, 2011

Property or Indexer my_class Cannot be Assigned to -- it is read only : C# Error

This is common C# error. Read Only Error occur when you try to assign values to a property or indexer, which is readonly. In other words the property do not have set accessors define. uncomment the below code and it will work.

using System;

namespace MyApp
{
    class my_class
    { 
        //int my_value;
        int I
        {
            get
            {
                return 1;
            }

            //set
            //{
            //    my_value = value;
            //}
        }

        static void Main(string[] args)
        {
            my_class obj = new my_class();
            obj.I = 20;  
            Console.ReadLine();
        }
    }
}

No comments:

Post a Comment

Sponsored Ad

Development Updates