Sponsored Ad

Tuesday, January 11, 2011

How to Implement ReadOnly Property using C#

If we can only read the value of property and not assign the value to property that is called Readonly property. Readonly property can be implemented using the only get accessor and do not implement set accessor.

How to Write ReadOnly Property in C#

C# Source Code:

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApp
{
    class Program
    {
        public static int my_value
        {
            get
            {
                return 12;
            }
        }
        static void Main(string[] args)
        {
            Console.WriteLine(my_value);
            //Error
            //my_value = 13;

            Console.ReadLine();
        }
    }
}

0 comments:

Post a Comment

Sponsored Ad

Website Update

Followers