Child pages
  • Access to a static member of a type via a derived type
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

This error arises in code that accesses a static member of a type via a type that was derived from it. For example:

The above code leads to the erroneous perception that the field N belongs to the type B, whereas it does not.

An even more confusing situation can arise from the call to a factory method. If you define a variable with var, the type you get may not be what you would expect. For example

The above code suggests that the result of the Create() operation is an object of type HttpWebRequest whereas it's not actually the case — the result is of type WebRequest and is best written as follows:

  • No labels