-1

I have a simple question which is confusing ..

Assume I have a class as Employee as follows

public Class Employee {

   public Int EmpID { get; set ;}
   public string EmpName { get; set ; }
}

Suppose web application creates instance of the object as follow

Employee obj = new Employee()
obj.EmpID = Int32.Parse(txtID.text)
obj.EmpName = txtName.text

If multiple instance of web application are executed(like 2 or 3 users using the web application at the same time) , then will the values of obj gets mixed up ?. Or is it unique to instance of web application running .

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
bp581
  • 859
  • 1
  • 16
  • 47

2 Answers2

3

then will the values of obj gets mixed up ?.

No never since you haven't defined class Employee [nor its properties] as static.

Or is it unique to instance of web application running .

Yes, they are unique. No matter, how many users is accessing your page, they will have a different instance of Employee object referring (or) pointing to different memory address in Heap area.

Rahul
  • 76,197
  • 13
  • 71
  • 125
1

It's Unique per object instance you create regardless if its the same user or a different one and is destroyed after it's out of scope or after the request by the GC. Unless you use static variables(see Here) or put that instance of the object into a session variable (unique to the user's session) or cache.

Community
  • 1
  • 1
Eric Kelly
  • 435
  • 3
  • 8