Click here to Skip to main content
16,017,881 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
You may find it illogical , but i feel its a genuine question:

Is there any reason why in C# we have to explicitly declare static class members as static

if they have to be static why isn't each member assumed to be static, saves precious typing time.
Posted

The simple answer is "because that is what the language specification says".

The "real" answer I don;t know - but it's likely to be a combination of
1) It was never a compiler requirement that the class static attribute should be automatically applied to child members, so it just didn;t happen.
And
2) It means that when you look at a method, property or field, you can tell immediately that it is static - you don't have to look for the class header declaration to know.

For me, the second one is important: the class header could well be pages away, and if you forget...

And how much "precious typing time" does it save? Two keys? Three? Unless you are a very slow typist, that's very, very trivial - and lot less that the time you would waste looking for the class header!

Saving "typing time" is a poor reason for doing anything: people who do that are often the same ones who habitually use var instead of entering the type definition without considering how much harder it makes the code to read of others; and who leave all controls at the Visual Studio default names because that saves them time as well.
 
Share this answer
 

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