Browse by Tags

Tagged Content List
  • Blog Post: Why is deriving a public class from an internal class illegal?

    In C# it is illegal to declare a class D whose base class B is in any way less accessible than D. I'm occasionally asked why that is. There are a number of reasons; today I'll start with a very specific scenario and then talk about a general philosophy. Suppose you and your coworker Alice are developing...
  • Blog Post: A method group of one

    I'm implementing the semantic analysis of dynamic expressions in Roslyn this week, so I'm fielding a lot of questions within the team on the design of the dynamic feature of C# 4. A question I get fairly frequently in this space is as follows: public class Alpha { public int Foo(string x) { ... } } ...
  • Blog Post: Hide and seek

    Another interesting question from StackOverflow. That thing is a gold mine for blog topics. Consider the following: class B { public int X() { return 123; } } class D : B { new protected int X() { return 456; } } class E : D { public int Y() { return X(); } // returns 456 } class P { public static...
  • Blog Post: Don't repeat yourself; consts are already static

    Today, another entertaining question from StackOverflow . Presented again as a dialogue, as is my wont. The specification says " even though constants are considered static members, a constant-declaration neither requires nor allows a static modifier ." Why was the decision made to not force constants...
  • Blog Post: Putting a base in the middle

    Here’s a crazy-seeming but honest-to-goodness real customer scenario that got reported to me recently. There are three DLLs involved, Alpha.DLL, Bravo.DLL and Charlie.DLL. The classes in each are: public class Alpha // In Alpha.DLL { public virtual void M() { Console.WriteLine("Alpha"); } } public class...
  • Blog Post: Why Can't I Access A Protected Member From A Derived Class? Part Six

    Reader Jesse McGrew asks an excellent follow-up question to my 2005 post about why you cannot access a protected member from a derived class . (You probably want to re-read that post in order to make sense of this one.) I want to be clear in my terminology, so I’m going to define some terms. Suppose...
  • Blog Post: Future Breaking Changes, Part Three

    As I said earlier , we hate causing breaking changes in our product, the C# compiler, because they cause our customers pain. Said customers are also software developers, and presumably they hate causing breaking changes for their customers as much as we do. We want to throw our customers into the...
  • Blog Post: Virtual Methods and Brittle Base Classes

    Hey, I'm back! And in my new location. That was the longest and least relaxing vacation I've ever taken. Fun, yes. Relaxing, no. And to top it off, my kitchen is not done yet. We're shooting for being able to run water tonight and actually use appliances by tomorrow night, but we'll see how it goes...
Page 1 of 1 (8 items)