2

I need to read XML file and store all the info inside variables/class when the software starts, and make the variables/classes be accessible every class.

With C++, I could use global variables or classes, even though it's not a good practice to have a global variables.

  1. If the variables/classes are read only data, what methods can I use for my purpose with C#?
  2. What if the variables/classes are read/write?

3 Answers 3

9

You could use a public static class, and make everything available from there. You could populate it with data at creation time. It won't technically be at global scope, but would make the data easily available, and you wouldn't explicitly have to instantiate anything.

Sign up to request clarification or add additional context in comments.

Comments

5

a static class with a static readonly variable

Comments

2

static class with static public variables
read/write can be done this way:

private int _someInt; public int SomeNumber{ public get {return _someInt;} private set {_someInt = value;} } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.