C# interfaces 🐟
HTML-код
- Опубликовано: 2 июл 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!");
}
}
}
} Наука
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
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! 🙏🏿
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.
After days of studying and going through lecture material on this topic, I was still clueless until your 5' tutorial came to the rescue. 🙏
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 RUclips 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.
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!
Your ability to explain such complicated things so simply is simply amazing to me.
Thank you for a great channel and quality content!
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
Most simple explanation I have seen on interfaces. Thank you!
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.
I have spent YEARS trying to understand this. today, i fully understood this in 5 minutes . WOW
God bless people like you who distill this information down to what is necessary without waffling on.
Fantastic explanation and example. It was very clear and understandable!
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. 👏👏👏
Best tutorials! So well planned and pedagogical!
Great explanation and cliff notes
Thanks for making the video so short and to the point
With a real practical example and less theory
After years, your tutorials still the best
IPrey for you 🙏
Cleared up a lot for my OOP exam tomorrow all from your videos. LEGEND
My guy just made an intermediate programming concept seem look like a beginner programming concept. Thank you Mr.Chad.
This was a clear explanation with great examples. Thank you!
Spent a couple of years learning C# online through RUclips 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.
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.
This code example helped me a lot to understand interfaces, thanks!
Simple but great explanation!
Thank you.
Was struggling with understanding this thanks for the clear explanation and solid examples :)
Quick and simple. Great job!
Better than the book I read. Thanks for a clear explanation.
Thanks, this was a really good approach to explaining the concept.
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...
A++ Explaination. Helped a lot.
Best explanation about interfaces. Thanks a lot. I have subscribed.
in just 5 min whole concept is clear...thanks a lot..
thank you so much! a concise and clear explanation!
Great basic explanation. Thank you!
Very helpful. Thank you!
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!!!!❤
thank you for explaining this :)
I finally understand interfaces now. Thanks!
Great explanation - thank you!
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.
Just gained a sub for such a clear explanation!
Best explanation of interfaces i've seen, thankyou :)
that's almost the half part of one of my finals, Thank you
perfect and compact explanation, thanks
This topic is very weird and this is a very good explanaition, thank you!
Really good video!
Good video. Thank you.
Tq Dude for explaining in simple way
Thanks bro. This was the missing link in my game project.
you're one of a kind!
Thank you!
Seeing video examples is so much better than seeing it being described in text for me
Thanks..Very helpful.
Excellent simple and undrestandable video for beginners or even intermidiate programmers!
Please do a video on Abtract classes vs Interface Classes.
best explanation with simple example
Amazing bro, thanks
Excellent explanation...
Bro code you are the best. Keep it up bro
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.
your vids are so helpful
I only know a little English and have a lot of difficulty listening to native speakers. Luckily, RUclips has an automatic translation function :D I'm from Vietnam, the video is really useful.
it's clear now think you so much
Not a bro but showing support. Thanks for the vid.
Thanks. Really Helpful.
Thanks!
this channel is a fucking goldmine. summarises my 1hr lecture into 5mins.
Thanks for the video Bro.
2:16 Rabbit... rabbit... equals new... Rabbit. Made me lol. Excellent video.
bro!!!! - awesome
Thx! I understand now XD
Thank you
Another great tutorial, if you had a patreon, i would definitely support it
chad bro saved me thanks man gg
Killed it
"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
thank you it was great!
thanks bro😄
Amazing u r a pro🤩
Thanks bro, helped a lot
Thanks
Thanks bro
ty
Thanks Bro!
You truly are a bro
Is there any chance you could do a video on dependency injection? I'm sure if you did, I could finally understand it.
You are such a bro, bro.
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?
Thanks man now I can be a brogrammer
I love u bro
Wow. Usually people need more than one video to win a sub from me, but you got it in just one!
Soldaat!
Simple clear fast.
Excellent explanations! Thank you. So far everything is very clear.
Now, suppose we have two classes Circle and Triangle that implement interfaces IShape.
How can I save the two or more classes in one xml file. What do I need to do? Can you provide an example?
No one shows us ways to save as a file that can be reused later.
nice, thx!
thank you