title: C# Static members
body: <p>I have a question regarding static members and functions of non static classes.</p>
  
  <p>I have a static member in my class that I use for authentication. Basically I call a static function from my web application and then inside I call a static function that assigns a value to that static member. Now my question is, will each call to a static function from my web application create a new reference to the object and assign a new value to the static member.</p>
  
  <p>So basically I have this:</p>
  
  <pre><code>public class ClassA
  {
       private static int UserId;
  
       private static AssignIdToUser(string token)
       {
           UserId = &lt;int value depending on result of db query&gt;;
       }
  
       public SendMessage(string token, string message, string toaddress)
       {
           AssignIdToUser(token);
           Message msg = new Message(); //This is just a sample of a class that is similar to the one I use
           msg.Message = message;
           msg.UserId = UserId;
           msg.ToAddress = toaddress;
           //add class to db and save
       }
  }
  </code></pre>
  
  <p>Then in my web application I can do:</p>
  
  <pre><code>ClassA.SendMessage("userstoken", "This is a message", "0123456789");
  </code></pre>
  
  <p>Now if two users log on at the same time and the function gets called at the same time will the member UserId have the correct value for each user?</p>
  
  <p>Basically is a instance of the object created for each request or is the same object used?</p>