Alex Rivera | Logout

Why does C# not allow const and static on the same line?

Asked 2009-05-09T03:51:21.853
27

Why does C# not allow const and static on the same line? In Java, you must declare a field as 'static' and 'final' to act as a constant. Why does C# not let you declare const's as final?

I make the further distinction that in Java, every interface is public and abstract, whether this is explicitly declared or not. Aren't const's effectively static in nature? WHy does C# balk at this?

Edit
Report

1 Answer

3

It is true that a C# const implies static BUT, C# has an equivalent to Java's final keyword in the keyword readonly.

So, in fact, C# allows a const final, it is static readonly in C#.

answered 2009-05-09T04:54:48.907

Your Answer