Beginner Questions
-
Hi. I am a new member of Code Project. I have some basic beginner questions, and wonder if this is the place to ask them. I'll ask one, and if there is a better area for beginner questions, please let me know. My current question involves the key word static. Could someone please give me an explanation of it's function? I am reading a Microsoft book on C#, and I am having trouble understanding what static is all about. I looked but do not find a FAQ on this site which answers such questions. Thanks, Steve
-
Hi. I am a new member of Code Project. I have some basic beginner questions, and wonder if this is the place to ask them. I'll ask one, and if there is a better area for beginner questions, please let me know. My current question involves the key word static. Could someone please give me an explanation of it's function? I am reading a Microsoft book on C#, and I am having trouble understanding what static is all about. I looked but do not find a FAQ on this site which answers such questions. Thanks, Steve
-
Hi. I am a new member of Code Project. I have some basic beginner questions, and wonder if this is the place to ask them. I'll ask one, and if there is a better area for beginner questions, please let me know. My current question involves the key word static. Could someone please give me an explanation of it's function? I am reading a Microsoft book on C#, and I am having trouble understanding what static is all about. I looked but do not find a FAQ on this site which answers such questions. Thanks, Steve
The static modifier, keeps the method,property, or field "static in memory". That means it persists and you don't need to instantiate it. You use them all the time when programming in .NET... one very good example is when you use any of the public members of Console such as Write() or Read(). The wole point behind a static keyword is to allow use of the so&so method/field without creating a new instance... How else would you be able to run any of the programs you write? Look at the general structure of a Main method. [STAThread] public static void Main(string[] args) { Application.Run(new Form1()); } you can run Main at anytime, and you create a new instance of the Form1 and then the program runs. Also, Application.Run() happens to be a static method as well :) Got a coding problem? Hand it to the CodeDevil!