Showing posts with label Constructs. Show all posts
Showing posts with label Constructs. Show all posts

Monday, July 18, 2005

My Classes Are Sealed

Continuing the theme tonight of talking about new C# keywords and language implementations (and comparing them to Java), I would be remiss if I didn't mention the keyword "sealed."

By marking a class "sealed" you prevent other classes from deriving from it. A sealed class, then, is sort of a one off. In contrast, you could also mark a class abstract (just like in Java -- behaves the same way too), which means that the class is made to be derived and cannot be instantiated itself.

readonly vs. const

I came across the "readonly" keyword haphazardly when I attempted to mark a static member variable as const. This is not possible in C#. Instead, use "readonly."