Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / March 2006

Tip: Looking for answers? Try searching our database.

static class Program in Program.cs in VS 2005

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Michael.Suarez@gmail.com - 02 Mar 2006 15:25 GMT
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?
David White - 02 Mar 2006 15:41 GMT
> 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.
Michael.Suarez@gmail.com - 02 Mar 2006 15:55 GMT
Thanks for the reply.

Any specific reason you wouldnt recommend this?
Nick Hounsome - 02 Mar 2006 16:23 GMT
> 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.
William Stacey [MVP] - 02 Mar 2006 22:22 GMT
| 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.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.