We pay for user submitted tutorials and articles that we publish. Anyone can send in a contribution
Learn MoreThis one could be easily become one of the Job Interview Questions we publish here at Dev102.com, but I decided to write a “regular” post about this issue because it is an important concept and not a just a puzzle or a brain teaser. Take a look at the following code, can you tell what will the output be?
public class BaseType { public BaseType() { Console.WriteLine("Call base ctor."); DoSomething(); } public virtual void DoSomething() { Console.WriteLine("Base DoSomething"); } } public class DerivedType : BaseType { public DerivedType() { Console.WriteLine("Call derived ctor."); } public override void DoSomething() { Console.WriteLine("Derived DoSomething"); } } public class MainClass { public static void Main() { DerivedType derived = new DerivedType(); Console.ReadLine(); } }
The output of this program is:
Did you ever need to convert List(T1) to List(T2)? One example might be when implementing an interface. you might need to expose a collection of other interfaces (or maybe the same interface), But you usually hold the concrete type implementing the interface in the collection. Lets look at the following example:
Copyright © 2012 Dev102.com
Breeze : Designed by Amit Raz and Nitzan Kupererd