Thursday, October 19, 2006


Today I learned that static variables declared in a generic base class are shared for all instances of all derived classes (in C#). I wrote code a while back assuming a separate copy of the static variables would exist for each derived class without thinking too much about the issue. Today I wrote my 2nd derived class and quickly found this was not true. I did correctly assumed all versions of a generic class would share the same static variable, but I wasn't 100% of this until today. I asked another experience developer and he wasn't sure either. We both agree this would be a great interview question (even if they don't know or get it wrong, it shows a lot about where their ability is with object oriented code). Fortunately, only 1 derived class made it to production before I found this.

This also goes to show:
  • No matter how well you think you know a language, you can always learn something new.
  • Being aware of what you don't know is valuable.
  • You should never make assumptions about things you can research and find out.


Post a Comment

<< Home