Examples of dynamic polymorphism in c

0 votes
I'm curious whether there are any further examples of dynamic polymorphism in C# besides method overriding. I know that method overriding is a type of dynamic polymorphism, but is this the only one?
Jun 6 in C# by rajiv
• 1,620 points
31 views

1 answer to this question.

0 votes

Check the example of polymorphism below. We have a class called 'SalaryCalculator' with a method called 'Calculate' and a parameter called 'IEmployee.' The 'Calculate' method has no idea what a 'IEmployee' is. Any class that implements the polymorphism 'IEmployee' can be used.

 class Program
{
    static void Main(string[] args)
    {
        Salarycalculator salaryCalculator = new Salarycalculator();
        salaryCalculator.calculate(new Architect());
    }


}

public class Salarycalculator
{
    public void calculate(IEmployee employee)
    {
        employee.CalculateSalary();
    }
}

public interface IEmployee
{
    void CalculateSalary();
}



public class Developer : IEmployee
{
    public void CalculateSalary()
    {

    }
}

public class Architect : IEmployee
{
    public void CalculateSalary()
    {

    }
}

}

The place receiving the object is where runtime polymorphism works, not the object initialization. 'calculate(IEmployee employee)' is an example where the 'Calculate' method only learns the type of 'IEmployee' at runtime. It can be of type 'Developer' or 'Architect,' which implies the 'Calculate' method will run polymorphically depending on the kind of object.

answered Jun 7 by pranav
• 2,580 points

Related Questions In C#

0 votes
1 answer

What are the differences between C, C# and C++ in terms of real-world applications?

C is a bare-bones, straightforward, and clean ...READ MORE

answered May 30 in C# by rajiv
• 1,620 points
29 views
0 votes
1 answer

How to find the extension of a file in C#

Go to here https://docs.microsoft.com/en-us/dotnet/api/system.io.path.getextension?redirectedfrom=MSDN&view=net-6.0#System_IO_Path_GetExtension_System_String_ string myFilePath = @"C:\MyFile.txt"; string ext ...READ MORE

answered Jun 21 in C# by jyoti
• 1,240 points
26 views
–1 vote
1 answer

Examples of GoF design patterns in .net

I am attaching some links. Go through ...READ MORE

answered Jun 23 in C# by krishna
• 2,540 points
16 views
0 votes
1 answer

C# - Can someone please show me a very simple example of Interfaces

Take this as example interface IFlyable { ...READ MORE

answered May 30 in C# by rajiv
• 1,620 points
24 views
0 votes
0 answers

The page cannot be displayed because an internal server error has occurred on server

When  I've deployed the website I installed  ...READ MORE

May 23 in Others by Kichu
• 19,040 points
188 views
0 votes
1 answer

Object Oriented Programming Basic Concept(C#)

Use this link https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/access-modifiers protected internal: The type or ...READ MORE

answered Jun 17 in C# by jyoti
• 1,240 points
18 views
0 votes
0 answers

How to create dependency injection for ASP.NET MVC 5

It's simple to create Dependency Injection using ...READ MORE

Jun 11 in C# by pranav
• 2,580 points
19 views
0 votes
1 answer

Authenticate on an ASP.Net Forms Authorization website from a console app

Essentially, we need to record a regular ...READ MORE

answered Sep 20, 2018 in IoT (Internet of Things) by Annie97
• 2,160 points
263 views
0 votes
1 answer

Encapsulation of subclasses from a constructor in C#

If you think about it in terms ...READ MORE

answered Jun 11 in C# by pranav
• 2,580 points
21 views
0 votes
1 answer

Which version of C# am I using

From developer cmd, type this csc -langversion:? This will ...READ MORE

answered Jun 7 in C# by pranav
• 2,580 points
21 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP