Skip to content

Instantly share code, notes, and snippets.

@jskeet
Created January 6, 2023 10:16
Show Gist options
  • Save jskeet/171df7bb64042855f4b3bab3b62e9c9a to your computer and use it in GitHub Desktop.
Save jskeet/171df7bb64042855f4b3bab3b62e9c9a to your computer and use it in GitHub Desktop.
using System;
public class Math
{
public virtual int Sum(int a , int b)
{
return a+b;
}
}
public class Class1 : Math
{
public int Sum(int a, int b)
{
return a + b + 10;
}
}
public class Class2 : Math
{
public override int Sum(int a, int b)
{
return a + b + 10;
}
}
class Program
{
static void Main()
{
Math math1 = new Class1();
Math math2 = new Class2();
Console.WriteLine(math1.Sum(5, 3)); // Prints 8
Console.WriteLine(math2.Sum(5, 3)); // Prints 18
}
}
@abouhamze-fahime
Copy link

thanks Jon Skeet I get your Idea that If we write the same method as base class the compiler ignore the derived class . thanks a lot and I delete my question

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment