Creating classes within classes

I know that the MS rules say this is not a good idea. However, I disagree, for example if a method takes a parameter which is an object, and this is not for an API., it is ok to create a class within a class when this class is meant to be used to pass stuff to this particular class only.

Better than putting it out in the open namespace, when it is tightly bound to this class only.

Sometimes, this is useful for an Enum also. Because then you can have enums with the same name, but within different classes. This often happens when writing code.

Comments

  1. "MS rules say this is not a good idea" can u please support this statement with any valid data?

    ReplyDelete
  2. MS rules will show warning if we create classes within classes. I just mean to say that sometimes this is desirable and even useful. For ex; some of the dataset and LINQ classes are classes within classes, putting everything in one namespace or having too many namespaces is a burden.

    ReplyDelete

Post a Comment

Popular posts from this blog

Tutorial: Using Google Cloud Storage from C# and .NET

Late 2008 Macbook only giving 1.5 gb/s speed with 6 gb/s Intel SSD?

The ridiculous interview experience