C# How To Use The Override And Virtual Method.

preview_player
Показать описание
G'day guys, In this video I will teach you how to can get started with override and virtual method in C#.

If you have any questions, leave a comment below.

Рекомендации по теме
Комментарии
Автор

For anyone that still doesn't know what the virtual keyword means - it tells a property or method in the base class that it will potentially be modified in a subclass. The "override" keyword makes a property or method overridden or "modified" in your subclass.

LandonHughes
Автор

This was helpful. I am learning C#, have been using Python for 18+ years where this happens naturally without having to write any "virtual" or "override", this bit me because the code seem to refuse to inherit. Had to add those two words in the places you mentioned to make it work.

zeycus
Автор

Thank you very much, the explanation was very clear it it helps me get the real idea of inheritance and Overriding. Really appreciate that

oubdamarthial
Автор

You did great dude, Thanks for the knowledge!

mingshengng
Автор

Thank you for helping me understand this. have a like.

zuque
Автор

Straight and to the point i love it. If ya'll ever locked up imma spam #FreeAndrew all over the place.

tien
Автор

You smashing that keyboard enter button SO HARD, thx for tutorial

killsan
Автор

Hi! Nice vid!! I've got a q
So, let me see if I got this right

If I have a class parent with
1.- instancing of public variables
2.- some methods to process that data, and
3.- some methods to output data
and then I create a children class
Then I only need to add the
- 1st thing and
- an override of the 3rd, for changes in output, if needed
because the 2nd is already being used from the parent class


did I get it wrong?

selfiestick
Автор

Here is the code written in this video: (note: I commented out the unused using statements on line 2, 3, 4, and 5.)
using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//using System.Threading.Tasks;

namespace ConsoleApp27
{
class Program
{
static void Main()
{
Student student = new Student("Andrew", "Eberle");


Teacher teacher = new Teacher("Harry", "James");

}
}
class Student
{
public string FirstName { get; set; }
public string LastName { get; set; }
public Student(string fn, string ln)
{
this.FirstName = fn;
this.LastName = ln;
}
public virtual string GetFullName
{
get
{
return "Student's Name: " + this.FirstName + " " + this.LastName;
}
}
}
class Teacher : Student
{
public Teacher(string fn, string ln) : base(fn, ln)
{
this.FirstName = fn;
this.LastName = ln;
}
public override string GetFullName
{
get
{
return "Teacher's Name: " + this.FirstName + " " + this.LastName;
}
}
}
}

oneilmw
Автор

Virtuals meaning is the opposite of static where as static is stationary and not changeable, virtual is changeable and not static.

Ytomany
Автор

Thank you Finally makes sense to me you are the real G !!!

armennagapetian
Автор

If you override students name with teacher and call student later down the line will it print teacher or student?

christianmjphotos
Автор

damn, i was taught to do all of that in different methods and classes

antoinealez
Автор

By trying to type fast, or talk fast, that wont make you better teacher... If this is supposed to be a tutorial, you should explain what you are doing, and not trying to type fast like crazy, just to show that you know how to code...

lgknmerp
Автор

Slow down typing dude. The backspacing is killing me.

DodgerDude