using System; namespace MyFirstProgram { class Program { static void Main(string[] args) { // static = modifier to declare a static member, which belongs to the class itself // rather than to any specific object Car car1 = new Car("Mustang"); Car car2 = new Car("Corvette"); Car car3 = new Car("Lambo"); Console.WriteLine(Car.numberOfCars); Car.StartRace(); Console.ReadKey(); } } class Car { String model; public static int numberOfCars; public Car(String model) { this.model = model; numberOfCars++; } public static void StartRace() { Console.WriteLine("The race has begun!"); } } }
I'm a beginner programmer. I feel like you have this innate ability to smash through all the knowledge that you have, and distill it all into what even a beginner can understand. It's so clear and concise. You just leave all that extra knowledge by the side and it keeps you from overexplaining. You're amazing.
@@khajiit5556 "Explain" doesn't mean the knowledge he poured into his student's head will stay there forever you get an explanation if u make use of it or not is up to you Oh and btw, if we use your logic to memories you have does it mean you didn't live through your early years or what?
I have been programming for years at a somewhat base level but I have had multiple people explain static to me and this video is the first time I've actually fully grasped the use of it and the power behind it. Thanks for the short but knowledge filled video.
I've been finding it pretty hard to understand concepts because every other resource i've used overexplains everything, you just make it clear and concise. I'm finally starting to understand, I didn't know I can learn the basics of static members in just 5 minutes. Thanks Bro Code!
Bro, you are a really brilliant teacher! For 10 years I have been struggling with this static thing. Now I understood it in 5 minutes. That is amazing!!! Thank you!
You should have seen me cheering up when you finally made this whole thing clear. Now I clearly understand what a static member means in a class. Thank you so much.
My college teacher just went through the comment bit explaining it but then didnt explain that whereas you have explained the explanation which i now understand, thanks
God bless u dude. i watched several videos some had weird Indian english, some just couldn't explain it in a way i could understand and some were both. 😒😒. finally understood what this static is. been coding for quite some time always tried my best to stay away from the word "static".
Yes. Abstract classes act as blueprints for other classes to inherit from while static classes serve as utility fixed classes. Quick example for static class: If you want to build a simple calculator, you can create a static class named Operations and have 4 static methods (add, subtract, division, multiply), each method will perform an operation with int a & b. To call it, simply put Operations.Add(1,2) in your main program. Other classes won't be able to modify the method and will not be able to create objects from this class. Quick example for abstract class: You want animals to make a sound. You will create an abstract class named Animals and create an abstract method MakeSound(), You're now preventing people from creating an object from Animal, which by itself is not an animal. Now you create a Dog class that inherits from Animal. Now you can override the MakeSound method to console write "bark". If you want to hear the bark, you need to create a Dog object and then call the method: class Dog : Animal Dog dog = new Dog(); dog.MakeSound(Console.WriteLine("Bark"); I hope this helps you or anyone else struggling to understand access modifiers. It's very important to know them well for professional success.
thanks for the video, really nice! I tried to use your code in Visual Studio and get error message: Compiler Error CS5001 " Program does not contain a static 'Main' method suitable for an entry point". Hence i cannot run it. Anything i can do to make it run and close this error message? Thanks !
using System;
namespace MyFirstProgram
{
class Program
{
static void Main(string[] args)
{
// static = modifier to declare a static member, which belongs to the class itself
// rather than to any specific object
Car car1 = new Car("Mustang");
Car car2 = new Car("Corvette");
Car car3 = new Car("Lambo");
Console.WriteLine(Car.numberOfCars);
Car.StartRace();
Console.ReadKey();
}
}
class Car
{
String model;
public static int numberOfCars;
public Car(String model)
{
this.model = model;
numberOfCars++;
}
public static void StartRace()
{
Console.WriteLine("The race has begun!");
}
}
}
My bro You're a G, thanks for the vid
I'm a beginner programmer. I feel like you have this innate ability to smash through all the knowledge that you have, and distill it all into what even a beginner can understand.
It's so clear and concise. You just leave all that extra knowledge by the side and it keeps you from overexplaining. You're amazing.
9 months later where's your knowledge at :D
@@khajiit5556 "Explain" doesn't mean the knowledge he poured into his student's head will stay there forever you get an explanation if u make use of it or not is up to you
Oh and btw, if we use your logic to memories you have does it mean you didn't live through your early years or what?
@@ch1nc2yk39 bro what are you saying😂
2 years, please tell me you've released a game ;-0
Best explanation of how we should use statics I have found.
I have been programming for years at a somewhat base level but I have had multiple people explain static to me and this video is the first time I've actually fully grasped the use of it and the power behind it. Thanks for the short but knowledge filled video.
I've been finding it pretty hard to understand concepts because every other resource i've used overexplains everything, you just make it clear and concise. I'm finally starting to understand, I didn't know I can learn the basics of static members in just 5 minutes. Thanks Bro Code!
1:52 I understood it right here. Wow that's cool.
Bro, you are a really brilliant teacher! For 10 years I have been struggling with this static thing. Now I understood it in 5 minutes. That is amazing!!! Thank you!
Bro thank you so much. THIS IS A HUGE HELP.
You should have seen me cheering up when you finally made this whole thing clear. Now I clearly understand what a static member means in a class. Thank you so much.
You are fantastic. Please never abandon us, keep on creating videos
Just started learning c# this is the best video i have seen to help explain static
1 month, you still going?
Went through like 5 videos explaining this topic and yours was the only one that made sense. Good stuff!
Great explanation and examples! Thank you!
Bro your explanation is superior
Extraordinary explanation. I should've starting watching your videos long time ago.
Very nice explanation for someone who's learning C# :)
No one explained this easier than you bro. Thank you so much!
I just found your channel and I love every video,v best explanations on RUclips
He's truly a Chad when it comes to explaining stuff.
My college teacher just went through the comment bit explaining it but then didnt explain that whereas you have explained the explanation which i now understand, thanks
Oh yeah, thanks for the video Bro.
God bless u dude. i watched several videos some had weird Indian english, some just couldn't explain it in a way i could understand and some were both. 😒😒. finally understood what this static is. been coding for quite some time always tried my best to stay away from the word "static".
The definitions you use are up to the point🏹
Amazing explanation! All of your examples are really good!
Best video about static i`ve watched. Thanks Bro.
Thanks bro.
Been following you since you had only 2k subscribers
Thanks! Had a blue locke awakening watching this
where have you been all my life
These videos are so easy to understand
Thanks Bro
Thank you i was trying to count within the class and could not figure it out this helps a ton!
Great that you write the code to your video .
Wow, so well explained. Genius! 🙏🏻🙏🏻🙏🏻 Thanks a lot! :D
thank you so much.
why are you so good at explaining???
these tutorials are god_tier
Your explanation is amazing! Thank you!!
That was easy
Love all of ur videos they answer the questionz that kept bothering me for so long . U earned a sub
Thank you,and good vídeo
This was GREAT! Thank you
clear and concise. thanks!
Very clear explanation, thanks!
AWESOME explanation!! Thank you!!
What a great video. Thanks
Bro, you explained this so well!
Awesome videos! Keep it up!
Excellent explanation!
Dude. thank you. Youre awesome
Finally a good explanation
That's great, now, I just know how to use static modifier, thanks..
So easy to understand. thank you.
great tutorial
This was so useful! Thanks man!
nicely explained
Thanks so much!
the best explanation thank you so much
You are awesome !
you are such a bro, bro.
nice explanation bro
Ive spent forever trying to understand why you would want to use static and it finally clicked.
Concise and great.
awesome tut!!! what's your vs theme btw?
nice explanation
good explaination
very clear thank you!
Just for me to Refresh memory, thanks
Thank you bro!
this code bro guy is really cool
Question: Is there any difference between using the static modifier vs the abstract modifier for a class?
Yes. Abstract classes act as blueprints for other classes to inherit from while static classes serve as utility fixed classes.
Quick example for static class: If you want to build a simple calculator, you can create a static class named Operations and have 4 static methods (add, subtract, division, multiply), each method will perform an operation with int a & b. To call it, simply put Operations.Add(1,2) in your main program. Other classes won't be able to modify the method and will not be able to create objects from this class.
Quick example for abstract class: You want animals to make a sound. You will create an abstract class named Animals and create an abstract method MakeSound(), You're now preventing people from creating an object from Animal, which by itself is not an animal. Now you create a Dog class that inherits from Animal. Now you can override the MakeSound method to console write "bark". If you want to hear the bark, you need to create a Dog object and then call the method:
class Dog : Animal
Dog dog = new Dog();
dog.MakeSound(Console.WriteLine("Bark");
I hope this helps you or anyone else struggling to understand access modifiers. It's very important to know them well for professional success.
Super @@jorgeandrespalma2134
amazing
Thanks Bro!
make my brain turn mushyyyy goooooshieeeeieiei
Thank you
perfect
Thanks
luv u bro
Thanks bruv
thanku bro
thanks!
nice!
It was so clear
true American programmer🤣🤣
Yessss
what about private static methods ? any good ?
noice
make my brain turn musshy gooooshiieiieei
lesson check😇
thanks for the video, really nice! I tried to use your code in Visual Studio and get error message: Compiler Error CS5001 "
Program does not contain a static 'Main' method suitable for an entry point". Hence i cannot run it. Anything i can do to make it run and close this error message? Thanks !
brabo
❤
i love u
Random comment years later
bzzz
the only bro we need is you not pewdiepie
Except, a car class shouldn't be keeping track of the number of cars there are and when the race has started.
Bro please explain goto statement in cpp
bro do you like unity game engine development
meow (as you asked for a random comment) :)
A random comment down below
:)
Random comnet
random comment down below
Wuttt