1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

C# oop static instance

  1. Dec 28, 2008 #1
    I have a question about instatiating a class as static and what that implies. Going through an old project of mine I noticed I did the following:

    public static Queue messageBuffer = new Queue();

    how does that static instance of the Queue behave compared to one declared without the static modifier? For example:

    public Queue messageBuffer = new Queue();

    Does it make a difference. I've played with both instances but cant tell the difference, but i want to make sure I know what I"m doing.

  2. jcsd
  3. Dec 28, 2008 #2
    Have you modified messageBuffer (both static and other) data (attributes) and checked what happens to data when you create second instance that contains this object?

    And, I would also suggest that some kind of output whenever Queue constructor is called (like Console.WriteLine("Queue is created") inside the Queue constructor.).
  4. Jan 3, 2009 #3
    The static keywords turns the field into a singleton, this also makes it possible to access it without creating the containing class by using Classname.messageBuffer.
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?

Similar Discussions: C# oop static instance
  1. Question about OOP (Replies: 2)