using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication1 { public interface Interface1 { void Test(); } public class BaseClass : Interface1 { public void Test() { throw new NotImplementedException(); //Execution jumps here always. I need it to execute this line only if Class1 doesn't have a Test function. } } public class Class1 : BaseClass { public void Test() { return; //Why not here? } } class Program { static void Main(string[] args) { Class1 a = new Class1(); Object obj = a as Object; Interface1 itf = a as Interface1; itf.Test(); // <-- Why it calls BaseClass.Test() ? } } }
public class BaseClass : Interface1 { public virtual void Test() { // some code here } } public class Class1 : BaseClass { public override void Test() { // some other code here } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)