Thursday 14 February 2013

We can create any number of objects to a class and each object we create will have separate memory allocation and any object doesn't reflect to the member's of other object. To test this rewrite the code under the Main method of class first as following:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CSharpConsole
{
    class First
    {
        int x = 100;
        static void Main()
        {
            First f1 = new First();
            First f2=new First();
            Console.WriteLine(f1.x + "   "+ f2.x);
            f1.x=500;
            Console.WriteLine(f1.x + "   "+ f2.x);
            Console.ReadLine();
        }
     }
}

No comments:

Post a Comment