Click here to Skip to main content
15,895,554 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi All
Why we are using static variable in a Static Method in C#


Thanks
Indrajit Dasgupta
Posted
Comments
Sergey Alexandrovich Kryukov 14-Jan-13 2:27am    
It is really hard to read the manuals?
—SA

1 solution

Key is: you need to understand the difference between instance methods and static methods[^].
Cheers
Andi
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 14-Jan-13 2:28am    
You did not address the variable. Will you?
I would start with stating that the static variables do not exist, only members can be static...
—SA
Andreas Gieriet 14-Jan-13 2:35am    
You are right, the wording of the question is not C# like - and I interpreted the question to be static members versus instance members.
Andi
Sergey Alexandrovich Kryukov 14-Jan-13 11:36am    
My point it: static fields and static methods are very different in nature, so fields need separate explanation.
You see, with methods, there are no memory location issues. Static and non-static methods are no different: the only difference is the hidden/implicit first parameter, "this", and the consequence is the difference in access to other instance members. With fields, storage is different.

Fields are either per class or per instance. All methods, even instance methods, are only per-class (perhaps, this point is not well understood by some).

—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900