Digambar Malla

Digambar Malla

  • NA
  • 5
  • 3.1k

Confusion about object

Mar 18 2013 1:12 PM
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 ???

Answers (1)