C# interfaces 🐟
Vložit
- čas přidán 2. 07. 2021
- C# interfaces tutorial example explained
#C# #interfaces #interface
using System;
namespace MyFirstProgram
{
class Program
{
static void Main(string[] args)
{
// interface = defines a "contract" that all the classes inheriting from should follow
// An interface declares "what a class should have"
// An inheriting class defines "how it should do it"
// benefits = security + multiple inheritance + "plug-and-play"
Rabbit rabbit = new Rabbit();
Hawk hawk = new Hawk();
Fish fish = new Fish();
rabbit.Flee();
hawk.Hunt();
fish.Flee();
fish.Hunt();
Console.ReadKey();
}
interface IPrey
{
void Flee();
}
interface IPredator
{
void Hunt();
}
class Rabbit : IPrey
{
public void Flee()
{
Console.WriteLine("The rabbit runs away!");
}
}
class Hawk : IPredator
{
public void Hunt()
{
Console.WriteLine("The hawk is searching for food!");
}
}
class Fish : IPrey, IPredator
{
public void Flee()
{
Console.WriteLine("The fish swims away!");
}
public void Hunt()
{
Console.WriteLine("The fish is searching for smaller fish!");
}
}
}
} - Věda a technologie
using System;
namespace MyFirstProgram
{
class Program
{
static void Main(string[] args)
{
// interface = defines a "contract" that all the classes inheriting from should follow
// An interface declares "what a class should have"
// An inheriting class defines "how it should do it"
// Benefit = security + multiple inheritance + "plug-and-play"
Rabbit rabbit = new Rabbit();
Hawk hawk = new Hawk();
Fish fish = new Fish();
rabbit.Flee();
hawk.Hunt();
fish.Flee();
fish.Hunt();
Console.ReadKey();
}
interface IPrey
{
void Flee();
}
interface IPredator
{
void Hunt();
}
class Rabbit : IPrey
{
public void Flee()
{
Console.WriteLine("The rabbit runs away!");
}
}
class Hawk : IPredator
{
public void Hunt()
{
Console.WriteLine("The hawk is searching for food!");
}
}
class Fish : IPrey, IPredator
{
public void Flee()
{
Console.WriteLine("The fish swims away!");
}
public void Hunt()
{
Console.WriteLine("The fish is searching for smaller fish!");
}
}
}
}
OMG, You are Amazing..
? ing - isn't a verb! Algiers racism - kidnap ID!
Interface declares: "What a class should have"
An inheriting class defines: "How it should do it"
Chef's kiss of an explanation, thanks sir
My teacher has spent hours confusing this for me. This was so clear
Teachers are so dumb nowadays
well, it is a bit more complicated than that. We can create a class object by using an interface and criss cross stuff. It becomes a bit complicated
adam ol aklını alırım
Your explanations are one of the clearest and easiest to remember ones I've ever come across. Great job!
I have seen other videos, and this is the best explanation i've seen so far. Thanks a lot. I've subscribed.
In an hour i'm writing an exam based on this. 10 minutes ago I knew shit about interfaces, now I know all I need. Huge thanks goes to this man! 🙏🏿
After days of studying and going through lecture material on this topic, I was still clueless until your 5' tutorial came to the rescue. 🙏
Zero BS, straight to the point. After watching your video I inmediately understood how to refactor my existing programs using Interfaces. Thank you very much!
getting into programing for game development as I have always been fascinated by it and your vids are the best I have found. You explain it in such a way that actually helps me learn. Most coding videos on CZcams are so hard to listen to as they don't know how to communicate their skills properly. But I thank you for doing such a good job with it as your videos help me a lot.
Your ability to explain such complicated things so simply is simply amazing to me.
Thank you for a great channel and quality content!
Bravo !!! Finally, someone’s demonstrated a concept without making the example so simple that you do not, first have to grapple your mind with the details of the example to understand the underlying concept. It is very rare to find an engineer who can communicate an idea concisely without confusing everyone. 👏👏👏
Great video thanks. I think thats the first time I understand what an interface does. Everyone keeps talking about contracts, but you are the first person to explain it in a way I can understand.
Most simple explanation I have seen on interfaces. Thank you!
This helped me so much I was so confused having to do this at my internship and I got the hang of it in 5 minutes because you explained this so well! Thank thank you
I have spent YEARS trying to understand this. today, i fully understood this in 5 minutes . WOW
Fantastic explanation and example. It was very clear and understandable!
God bless people like you who distill this information down to what is necessary without waffling on.
best explanation with simple example
Best tutorials! So well planned and pedagogical!
Cleared up a lot for my OOP exam tomorrow all from your videos. LEGEND
After years, your tutorials still the best
IPrey for you 🙏
This was a clear explanation with great examples. Thank you!
Simple but great explanation!
Thank you.
Great explanation and cliff notes
Thanks for making the video so short and to the point
With a real practical example and less theory
My guy just made an intermediate programming concept seem look like a beginner programming concept. Thank you Mr.Chad.
in just 5 min whole concept is clear...thanks a lot..
Better than the book I read. Thanks for a clear explanation.
Thank you very much. I'm from Brazil, and I know a litlle bit English, and these help me to understand what you were explaining, and the form how you were explaining was so simple, I could learn about the interfaces.
Best explanation about interfaces. Thanks a lot. I have subscribed.
This code example helped me a lot to understand interfaces, thanks!
Quick and simple. Great job!
Was struggling with understanding this thanks for the clear explanation and solid examples :)
A++ Explaination. Helped a lot.
thank you so much! a concise and clear explanation!
Great basic explanation. Thank you!
I am starting to love your videos... They are short, precise... AND VERY EASY TO UNDERSTAND THE WAY YOUUUU EXPLAIN IT!!! Keep the great work BRO...
Best explanation of interfaces i've seen, thankyou :)
perfect and compact explanation, thanks
Tq Dude for explaining in simple way
Spent a couple of years learning C# online through CZcams videos, I learned alot to the point where I created a console program to make pizzas from scratch. The program I wrote allowed me to input keys to the console that allowed option selection. I learned that through Michael Hadley's Intro to Programming tutorials.
However I struggled like a muddabucka with a few things to this day. Interfaces being one them. Today I am on Unity exploring real game design, and their lesson courses are amazing. All the C# know-how I learned proved worth it, because I am flying through the courses - because Unity's documentation doe alot of work for you. But there was a course that used IEnumerators in Unity.
Sure I understood what the IEnumerator as for - but I still never understood Interfaces themselves. Now I do thanks to your video. And i's such a clear and easy concept i feel so dumb tonot have grasped them before.
But thanks man! ... I mean... Bro.
Thanks, this was a really good approach to explaining the concept.
I finally understand interfaces now. Thanks!
WOW, Amazing... i was Struggling for 3 Months. Today i Got the ReaL idea. Thank You So Much
That was really helpful Thank You!
Great! Saved me alot of time which i was wasting on reading nonscense books!! Now i know what are Interfaces!!!!❤
Great explanation - thank you!
Very helpful. Thank you!
This topic is very weird and this is a very good explanaition, thank you!
thank you for explaining this :)
Excellent explanation...
Just gained a sub for such a clear explanation!
Good video. Thank you.
Really good video!
Thanks..Very helpful.
Seeing video examples is so much better than seeing it being described in text for me
2:16 Rabbit... rabbit... equals new... Rabbit. Made me lol. Excellent video.
that's almost the half part of one of my finals, Thank you
Bro code you are the best. Keep it up bro
Thanks for the video Bro.
Thanks. Really Helpful.
Thanks very clear. The multiple inheritance is good. But in my experience it seems most projects tend to have a one-to-one model where each class has an interface all to itself that is never implemented elsewhere, hence overkill.
your vids are so helpful
Amazing bro, thanks
Thanks bro. This was the missing link in my game project.
Excellent simple and undrestandable video for beginners or even intermidiate programmers!
Please do a video on Abtract classes vs Interface Classes.
Good explenation
Thank you
Amazing u r a pro🤩
Thank you!
Not a bro but showing support. Thanks for the vid.
it's clear now think you so much
"The world isn't perfect. But it's there for us, doing the best it can....that's what makes it so damn beautiful" - Roy Mustang
Soldaat!
this channel is a fucking goldmine. summarises my 1hr lecture into 5mins.
nice video
Thanks
Thanks bro
bro!!!! - awesome
you're one of a kind!
Good video. Just one point, a class is said to implement an interface and to inhererit from another class. Also, it would be good if you perhaps demonstrated why a dev may choose to use interfaces. E.g. polymorphism and dependency injection, for example.
Killed it
thanks bro😄
Thanks!
Another great tutorial, if you had a patreon, i would definitely support it
thank you it was great!
Simple clear fast.
I don't understand what the itnerface actually does. by defining the method of fleeing and hunting in every class does that not make the inheritance obsolete?
I only know a little English and have a lot of difficulty listening to native speakers. Luckily, CZcams has an automatic translation function :D I'm from Vietnam, the video is really useful.
Thanks bro, helped a lot
chad bro saved me thanks man gg
Thx! I understand now XD
thank you
Thanks Bro!
Thanks man now I can be a brogrammer
THANKS +1 SUBSCRIBER
You are such a bro, bro.
I love u bro
ty
You truly are a bro
Damm, I couldn't understand what that is for months in my uni, and I suddenly understand it in 5 min after finding this viedo