Home > other >  In c #, please what is the difference between the public and public static??
In c #, please what is the difference between the public and public static??

Time:09-27

What is the difference between both the scope?

CodePudding user response:

Both are public, can be called outside,
Is static, without static to instantiate, with the object of the class to point out,
With the static is static, point it out directly with the name of the class,

CodePudding user response:

reference 1/f, green millions of reply:
both are public, can be called outside,
Is static, without static to instantiate, with the object of the class to point out,
With the static is static, point it out directly with the name of the class,
understanding! But why want to use static? Where is the static use?

CodePudding user response:

The two bad static,
Static is static, do not need to manually instantiate can use the
Static methods like function, static variables numerical unity can be maintained or retain current value next reoccupy

CodePudding user response:

reference RSZE reply: 3/f
both static poor,
Static is static, do not need to manually instantiate can use the
Static methods like function, static variables numerical unity can be maintained or retain current value next reoccupy
thank??

CodePudding user response:

Stored in the memory space static and non-static vary under the condition of static front if not necessary don't use public including sure don't need package use public also want to use less otherwise there will be a lot of problems

CodePudding user response:

The static modified variable or function, static area kept in memory, the memory will last until the end will be released

New out of the object is stored in the memory in the heap, need to manually delete, or release end of the program, but c # to do the garbage collection mechanism, when the reference count is zero, will automatically release, so don't consider the release of

Variables defined in normal function such as: int val=0; Is the memory allocated in the stack, when the function of the stack, memory release,

Conclusion: the modified keyword, are used to tell the compiler that the object where the preservation, namely tells the compiler, when to release this object

CodePudding user response:


There are some things need global Settings
For example, a thread pool is a static class
Don't need to instantiate can modify
After all, a applications only need a pool don't need multiple

For some static members are generally is used to store the class all instances can use data

CodePudding user response:

Is static, without static to instantiate, with the object of the class to point out,
With the static is static, point it out directly with the name of the class

CodePudding user response:

Still didn't know when to and when not in use use static feeling doesn't affect the outcome more than just write less the instantiation of the operation step

CodePudding user response:

So I if I say with you a case of a script with a static variable asd I asd can be directly used in b script reference a.a sd to access the change in method is the same