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

0 votes
I'm having trouble understanding how to use interfaces and why they're necessary. Could someone provide me a basic example?
May 30 in C# by pranav
• 2,580 points
14 views

1 answer to this question.

0 votes

Take this as example

interface IFlyable
{
    void Fly();
}

class Bird : IFlyable
{
    public void Fly() { }
}

class Plane : IFlyable
{
    public void Fly() { }
}

List<IFlyable> things = GetBirdInstancesAndPlaneInstancesMixed();
foreach(IFlyable item in things)
{
   item.Fly();
}

Although Bird and Plane share no common base class other than Object, we can deal with them as a group in our software by utilising the same interface because they have the same "feature": Fly

answered May 30 by rajiv
• 1,620 points

Related Questions In C#

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
11 views
0 votes
1 answer

Switch case: can I use a range instead of a one number

To categorise your switch circumstances, I would ...READ MORE

answered Jun 13 in C# by krishna
• 1,460 points
9 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
16 views
0 votes
0 answers

Use of interfaces, practical and real world example

I've been attempting to figure out what ...READ MORE

Jun 11 in C# by krishna
• 1,460 points
2 views
0 votes
3 answers

Trying to upload files using Selenium(C#)

You can try using Javascript Executor to ...READ MORE

answered Aug 23, 2019 in Selenium by Abha
• 28,100 points
4,468 views
0 votes
1 answer

Deploy my Windows 10 IOT core application locally!

Of course, you, can! That is, in ...READ MORE

answered Jul 17, 2018 in IoT (Internet of Things) by nirvana
• 3,130 points
499 views
+6 votes
16 answers

How do backend of these really cool games work?

Most of the games these days don't ...READ MORE

answered Jul 19, 2018 in Career Counselling by Kalgi
• 52,350 points
7,255 views
0 votes
1 answer
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
23 views
0 votes
1 answer
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