Since there is no chance to learn to write large projects, there is little detailed analysis
Public; Private;
Static; Private
Static;
Public
Static. Today, my head suddenly becomes blank. After two hours of searching for information, I got the following content and posted it specially. I hope I can help some young friends. You are also welcome to point out my mistakes or omissions.
Public: Public. Function: Used to declare public variables or methods. That is, it can be referenced outside the class that declares the variable or method.
PRIVATE: private. It is used to declare internal private variables or methods. That is, it cannot be referenced outside the class that declares the variable or method.
Static: Static. It is used to declare the variables or methods directly called using this class. Directly use this keyword (addPublic(Note: static variables can only be obtained through classes in C .), Variables or methods can be referenced externally.
The following is an example:
PublicClass gettime
{
PublicString time ()
{
Return System. datetime. Now. tolongdatestring ();
}
Private string time1 ()
{
Return System. datetime. Now. tolongdatestring ();
}
PublicStaticString time2 ()
{
Return System. datetime. Now. tolongdatestring ();
}
}
All the above three methods return the current time. Let's take a look at the differences between the three methods. In C #, The New Keyword is widely used, assume that this class is referenced in another class.
PublicClass tsting
{
Gettime n_gettime = new gettime ();
String time = n_gettime.time (); // here, you can access the gettime method, which isPublicThe other two classes cannot be accessed. To access time2., you only need to write samples.
Sting time2 = gettime. time2 ();
// Time1 () declared with the private keyword cannot be accessed externally .}
UseStaticThere is also an essential difference from not to use, that is, when a variable is declared, if its own value is 0, after the value is one hundred, ifStaticIf the keyword is not used, it is 0.
(If any expert finds an error, please help !)