|
-
Jun 25th, 2006, 04:01 PM
#1
Thread Starter
Lively Member
[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
-
Jun 25th, 2006, 05:22 PM
#2
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.
-
Jun 26th, 2006, 04:06 PM
#3
Re: [2.0] static variables in an app that can only open one file at a time
-
Jul 2nd, 2006, 08:44 PM
#4
Thread Starter
Lively Member
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
-
Jul 3rd, 2006, 04:42 AM
#5
Re: [2.0] static variables in an app that can only open one file at a time
Yoda is wise.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|