[2.0] static variables in an app that can only open one file at a time
if my app can only have one file open at a time, is it a good idea to start sticking static methods all over my code? such as:
Code:
internal static class Program {
public static MyFileClass curFile;
// ...
}
Code:
internal class MainForm : Form {
public static MainForm inst;
public MainForm() {
inst = this;
InitializeComponent();
}
// ...
}
i know that seems kind of vague, but i began coding a project and didn't plan well, so some methods took a MyFileClass as a parameter while some just used the static variable. Which would be a better idea?
Thanks in advance,
John
Re: [2.0] static variables in an app that can only open one file at a time
The "static" key word doesn't just exist for convenience. If a variable, property or method is logically a member of the class, rather than a member of an instance of that class, then it should be declared static.
Re: [2.0] static variables in an app that can only open one file at a time
Re: [2.0] static variables in an app that can only open one file at a time
doh! thanks. btw that's the best discussion of singletons in c# i've seen so far. thanks :thumb:
Re: [2.0] static variables in an app that can only open one file at a time