• 0

[C#] Question about static variables


Question

Just a quick Q, to make sure I'm writing this piece of code right. I've got a class with nothing but static variables and two classes that need to use that class. Class 1 is in the main application, and class 2 is in a dynamically-loaded assembly. Will both class 1 and 2 use the same instance of the variables? In other words, does class 2 get a separate copy of all of the static variables because it's not really part of the application?

Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 0

Well, no; they're static. All instances of the class share the same static variables, that's what static variables are for. But I don't know if that applies to classes that are dynamically loaded into the appdomain.

Link to comment
Share on other sites

  • 0

Yes, they should. The static variables are stored in your application's instance, so it doesn't matter which assembly is accessing it.

Test it out, just in case I'm wrong :p

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.