C# method overriding 🙅

  Рет қаралды 50,065

Bro Code

Bro Code

Күн бұрын

Пікірлер: 59
@BroCodez
@BroCodez 3 жыл бұрын
using System; namespace MyFirstProgram { class Program { static void Main(string[] args) { //method overriding = provides a new version of a method inherited from a parent class // inherited method must be: abstract, virtual, or already overriden // Used with ToString(), polymorphism Dog dog = new Dog(); Cat cat = new Cat(); dog.Speak(); cat.Speak(); Console.ReadKey(); } } class Animal { public virtual void Speak() { Console.WriteLine("The animal goes *brrr*"); } } class Dog : Animal { public override void Speak() { Console.WriteLine("The dog goes *woof*"); } } class Cat : Animal { } }
@DivanProdOfficial
@DivanProdOfficial 3 жыл бұрын
so short and effective!! thank you for not wasting my time!
@marionella175
@marionella175 2 жыл бұрын
Wow! I've spent more than 15 minutes listening to a video on my C# course about it, I almost fell asleep and absolutely didn't get how method overriding works, BUT 2 minutes of your video and I get it so clear. Thank you very much!
@valenzsa418
@valenzsa418 Жыл бұрын
Thank you! This clarifies my confusion as to when and the difference that a method can be overriden if whether its from a regular class or abstract class.
@DoubleShakey
@DoubleShakey 2 жыл бұрын
bro,.. great videos, so simple and straight to the point. good review!
@muhammadtaha4208
@muhammadtaha4208 6 күн бұрын
Explained it way better in 4 minutes than what my teacher couldnt in 4 months
@abdelrahmangomaaabbady
@abdelrahmangomaaabbady Жыл бұрын
Wonderful tutorial, great thanks.
@MrSK168
@MrSK168 Жыл бұрын
Very good explanations! Thanks for sharing.
@nikunjsethi9351
@nikunjsethi9351 11 ай бұрын
Thanks for the explanation
@thisdeath
@thisdeath 4 ай бұрын
3:30 reminded me of gin ibushi hahaa but nice video 😁👍
@linus3k
@linus3k Жыл бұрын
very good vid, to the point and very good explanation.
@raquelmarino4616
@raquelmarino4616 3 ай бұрын
bro is always saving me for my assignments in the shortest amount of time
@badrbennani3801
@badrbennani3801 2 жыл бұрын
very helpful video. thanks
@goverdhanjayaram3683
@goverdhanjayaram3683 Жыл бұрын
Super effective !! Thank you !
@vishwajeetpanwar3271
@vishwajeetpanwar3271 3 жыл бұрын
VRO thanks Short and Effective just perfect
@qnghost253
@qnghost253 Жыл бұрын
Simple and helpful
@adambosick3137
@adambosick3137 10 ай бұрын
Keep the content coming.
@FullExtension1
@FullExtension1 2 жыл бұрын
you are such a bro, bro.
@JugalSingh
@JugalSingh Жыл бұрын
great video
@Bear-nr9jo
@Bear-nr9jo 3 жыл бұрын
Great vid bro, you helped me understand c# :D
@sainikhithakadam4939
@sainikhithakadam4939 8 ай бұрын
Thank you
@spartanranger
@spartanranger 3 жыл бұрын
Thanks for the video Bro.
@TheMursol
@TheMursol Ай бұрын
Thank you bro !
@johneconomou567
@johneconomou567 2 жыл бұрын
broooooooooo amazing
@liberjesus9375
@liberjesus9375 5 ай бұрын
This is that good that I saved around 100 lines of code
@Dadax9398
@Dadax9398 3 жыл бұрын
The thumbnails always get me x)
@amalamel6727
@amalamel6727 Жыл бұрын
Thanks
@mertkurt947
@mertkurt947 Жыл бұрын
yea maaaaaaaaan , super helpful
@milorday5141
@milorday5141 Жыл бұрын
thank you
@sametayaz4891
@sametayaz4891 Жыл бұрын
what does the fox say?
@Eldritch_
@Eldritch_ 8 ай бұрын
a random comment down below
@pajkeav
@pajkeav 2 жыл бұрын
nice
@FaizyPlayz786
@FaizyPlayz786 Жыл бұрын
@triton5457
@triton5457 2 жыл бұрын
good vid bro
@cn-ml
@cn-ml 3 жыл бұрын
My compiler says the derived class has to use either override or new? What is new used for in this context?
@MSport030
@MSport030 4 ай бұрын
What does the catdog go?
3 жыл бұрын
Thanks Bro!
@AmanSharma-hg2wy
@AmanSharma-hg2wy Жыл бұрын
@courtneywoodcock5696
@courtneywoodcock5696 2 жыл бұрын
thanks
@definitelynotchris4776
@definitelynotchris4776 3 ай бұрын
woof
@BenBerke
@BenBerke 2 жыл бұрын
so whats the point of overriding? Why not just create a new method that just prints a line?
@thendar823
@thendar823 2 жыл бұрын
Ill put my comment here so in case someone smarter than me comes along and gives an explanation, I can read it too
@RalphBrandsma
@RalphBrandsma 2 жыл бұрын
The point of overriding in this case is that with his structure all animals that inherit from the base class have a method Speak() which creates uniformity. when writing the base class, an animal that is not specific makes a **brr** noise. A possibly better example is if you have a game, for instance, with a base class: Sword that has the method Attack() that has a 20% chance to hit, and an inherited class: MagicSword. with this setup all Swords and MagicSwords can have the method Attack() called, but what if when attacking, the magic sword always hits because *magic*. well that is a good use for overrides as you can override the Sword implementation of Attack() and you would still be able to treat it as a sword as shown below. If you instead had individual Attack() methods, then the base class cannot have a method named Attack(), so any generic swords would be unable to attack. **EXAMPLE** using System; namespace Example { class Program { static void Main(string[] args) { List mySwords = new List(); mySwords.Add(new Sword()); mySwords.Add(new MagicSword()); foreach (var sword in mySwords) { sword.Attack(); } Console.ReadKey(); } } class Sword { public virtual void Attack() { Random random = new Random(); float chanceToHit = random.NextSingle(); if (chanceToHit > 0.2f) { Console.WriteLine("Success!"); } else { Console.WriteLine("You Missed!"); } } } class MagicSword : Sword { public override void Attack() { Console.WriteLine("Success!"); } } }
@whitedinamo
@whitedinamo 3 жыл бұрын
lesson check😇
@abhinay4200
@abhinay4200 Жыл бұрын
What about new Keyword what happens when parent method is virtual and child is new
@EchoVids2u
@EchoVids2u 3 жыл бұрын
Why does it still work without putting override and virtual
@nolle
@nolle 2 жыл бұрын
my guess is that you create a new method (with the same name) within that object, which is still valid and will work but it's not a good idea
@abdesslemebenhassine4250
@abdesslemebenhassine4250 8 ай бұрын
it is useless here u could type it directly without virtual , override right ?
@Дмитрий-п9ь7щ
@Дмитрий-п9ь7щ 6 ай бұрын
Not useless. For example, you need a method for many objects, that derive from one class. But SOME of these objects are exceptions and each of them needs a different method
@Astroweasels
@Astroweasels 2 жыл бұрын
But what does the fox say?
@larrytedmcbride
@larrytedmcbride 8 ай бұрын
Random Comment 🤠👍
@ab_obada5012
@ab_obada5012 6 ай бұрын
Random Comment Down Below!!!
@McPatoo
@McPatoo Жыл бұрын
🗿🗿🗿🗿🗿 Done!
@the_dude_josh
@the_dude_josh Жыл бұрын
A random comment down below.
@o_BudgetGames
@o_BudgetGames 2 ай бұрын
random coment here below
@Proviper666
@Proviper666 2 жыл бұрын
1
@LuizHenrique-gm1cc
@LuizHenrique-gm1cc Жыл бұрын
Thanks bro!
@פרחיהיקינטון
@פרחיהיקינטון 10 ай бұрын
thanks
C# ToString method 💭
3:28
Bro Code
Рет қаралды 29 М.
C# polymorphism 🎭
5:11
Bro Code
Рет қаралды 91 М.
Support each other🤝
00:31
ISSEI / いっせい
Рет қаралды 81 МЛН
So Cute 🥰 who is better?
00:15
dednahype
Рет қаралды 19 МЛН
Chain Game Strong ⛓️
00:21
Anwar Jibawi
Рет қаралды 41 МЛН
Learn C#: Abstract or Virtual Method, Which Fits Better Here?
7:31
Method overriding and method overloading in c# | c# tutorial #16
10:04
Ravindra Devrani
Рет қаралды 2 М.
Naming Things in Code
7:25
CodeAesthetic
Рет қаралды 2,3 МЛН
how Google writes gorgeous C++
7:40
Low Level
Рет қаралды 990 М.
#52 Method Overriding in Java
7:57
Telusko
Рет қаралды 178 М.
C# constructors 👷
5:44
Bro Code
Рет қаралды 92 М.
C#: Method Modifiers: Virtual/Override, Abstract, and Static
8:55
Edward Tanguay
Рет қаралды 6 М.
C# inheritance 👪
4:29
Bro Code
Рет қаралды 65 М.
C# - Method Overriding
12:46
TutorialsPoint
Рет қаралды 24 М.
Master Pointers in C:  10X Your C Coding!
14:12
Dave's Garage
Рет қаралды 341 М.
Support each other🤝
00:31
ISSEI / いっせい
Рет қаралды 81 МЛН