Thursday, 14 February 2013

Every member of a class(variable or method) it it is non--static can be accessed under the Main method only by using object of class. A variable of a class is a copy of the class which is not initialized.
                        obj ----> null

An object of a class is a copy of a class which is initialized using new keyword and the memory is allocated for an object of class.
                        obj --->100=x

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

namespace CSharpConsole
{
    class First
    {
        int x = 100;
        static void Main()
        {
            First obj = new First();
            Console.WriteLine(obj.x);    //obj is a object or instance 
            
            Console.ReadLine();
        }
     }
}
// It will print the value of x=100

No comments:

Post a Comment