Search
Winners

Win Prizes

Social Presence
Like us on Facebook
Advertisements
Ads

Want to know the difference

Rks2rk
Posted by Rks2rk under C# on 3/14/2013 4:59:56 PM | Points: 75 | Views : 3302 | Status : [Member]

class demo
    {
        int x=10;
        public demo()
        {
        }
        static void Main()
        {
            Console.WriteLine(new demo().x);    //1st line
            new demo().x = 20;                   //2nd line
            Console.WriteLine(new demo().x);
            demo d2=new demo();
            d2.x = 30;                           //3rd line
            Console.WriteLine(d2.x);            
            Console.ReadLine();
        }
    }

What is the difference between 1st,2nd and 3rd line ??? Why the value is not assigned in 2nd line where as it is assigned in 3rd line ???



Comments or Responses


Login to post response