|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
static class Program in Program.cs in VS 2005When 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? Michael.Sua***@gmail.com wrote:
> When you create a new windows application in VS 2005, you have a I have removed the static attribute from this class and see no problems with > 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? > 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. Thanks for the reply.
Any specific reason you wouldnt recommend this? <Michael.Sua***@gmail.com> wrote in message
news:1141313140.948692.314450@i39g2000cwa.googlegroups.com... You can do what you want with it as it is never regenerated and there is no > 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? 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. |
|||||||||||||||||||||||