static class Program in Program.cs in VS 2005

  • Thread starter Thread starter Michael.Suarez
  • Start date Start date
M

Michael.Suarez

When you create a new windows application in VS 2005, you have a
Program.cs file which declares the class Program as static. Is there
any reason that this MUST be static? I want to take the work static out
so that I can declare a variable that is a member of Program so that it
can be accessed globally by all other forms in the project. Any
forseeable problems in doing this?
 
When you create a new windows application in VS 2005, you have a
Program.cs file which declares the class Program as static. Is there
any reason that this MUST be static? I want to take the work static out
so that I can declare a variable that is a member of Program so that it
can be accessed globally by all other forms in the project. Any
forseeable problems in doing this?

I have removed the static attribute from this class and see no problems with
doing so. The main() method must remain static, I believe.

Of course, while I don't recommend the practice, you should be able to simply
add a static variable to the class as-is. With the correct scope, it could be
visible by callers in your application.
 
When you create a new windows application in VS 2005, you have a
Program.cs file which declares the class Program as static. Is there
any reason that this MUST be static? I want to take the work static out
so that I can declare a variable that is a member of Program so that it
can be accessed globally by all other forms in the project. Any
forseeable problems in doing this?

You can do what you want with it as it is never regenerated and there is no
magic about it.

I would suggest however that instead you create your own class and view
Program as a bit of template magic. That way, if MS, should decide to put
anything else in there in the future it will not cause a problem.
 
| I would suggest however that instead you create your own class and view
| Program as a bit of template magic. That way, if MS, should decide to put
| anything else in there in the future it will not cause a problem.

Agree.
 
Back
Top