Accessing private data using accessor method in C#


Imtroduction:
In this articals we will look how to use Accessing private data using Accessor methods in C#.one of the design of object oriented systems is not to permit any direct access of the implication of integrity.it is a normal practice to provide special method known as accessor method to have access to data member.we must use only method to set  or retrieve the value of these members.this program shows how accessor methods can be used to set and get the value of a private data member. 
Example:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Number
{
    private int number;
    public void SetNumber(int x)
    {
        number=x;

    }

        public int GetNumber()
        {
            return number;
        }
}
class NumberTest
{
    
    
    public static void Main()
    {
        Number n=new Number ();
        n.SetNumber(1000);
        Console.WriteLine ("Number="+n.GetNumber());

    }
}
Output of program:

upload.gif

Thank U. if U have any Suggestions and Comments about my blog, Plz let me know.