Versioning with the Override and New Keywords (C# Programming Guide)

Anyway, I think keyword new for versioning should be avoided as much as possible..
Here is small example:

	public static void RunSnippet()
	{
		Child child = new Child();
		child.Run();
		Intermediate intermediate = new Child();
		intermediate.Run();
		Base bs = new Child();
		bs.Run();
		IClass interf = new Child();
		interf.Run();
		IClass ch2 = new Child2();
		ch2.Run();
	}

	public class Child2 : Intermediate, IClass
	{
		public new void Run()
		{
			WL("Child");
		}
	}

	public class Child : Intermediate
	{
		public new void Run()
		{
			WL("Child");
		}
	}

	public class Intermediate : Base
	{
	}

	public class Base : IClass
	{
		public void Run()
		{
			WL("Base");
		}
	}

	public interface IClass
	{
		void Run();
	}

which produces output:

Child
Base
Base
Base
Child



Write a comment



    
Answer to Life, the Universe, and Everything is based on WordPress platform, RSS tech , RSS comments design by Gx3.