C# objects 🧍♂️
Ғылым және технология
C# object oriented programming tutorial example explained
#C# #objects #classes
using System;
namespace MyFirstProgram
{
class Program
{
static void Main(string[] args)
{
// object = An instance of a class
// A class can be used as a blueprint to create objects (OOP)
// objects can have fields & methods (characteristics & actions)
Human human1 = new Human();
Human human2 = new Human();
human1.name = "Rick";
human1.age = 65;
human2.name = "Morty";
human2.age = 16;
human1.Eat();
human1.Sleep();
human2.Eat();
human2.Sleep();
Console.ReadKey();
}
}
class Human
{
public String name;
public int age;
public void Eat()
{
Console.WriteLine(name + " is eating");
}
public void Sleep()
{
Console.WriteLine(name + " is sleeping");
}
}
}
Пікірлер: 80
using System; namespace MyFirstProgram { class Program { static void Main(string[] args) { // object = An instance of a class // A class can be used as a blueprint to create objects (OOP) // objects can have fields & methods (characteristics & actions) Human human1 = new Human(); Human human2 = new Human(); human1.name = "Rick"; human1.age = 65; human2.name = "Morty"; human2.age = 16; human1.Eat(); human1.Sleep(); human2.Eat(); human2.Sleep(); Console.ReadKey(); } } class Human { public String name; public int age; public void Eat() { Console.WriteLine(name + " is eating"); } public void Sleep() { Console.WriteLine(name + " is sleeping"); } } }
@BananaMan6763
2 ай бұрын
Radical!
@hingsing1
Ай бұрын
Thanks for pasting the code as well. Question- How come when you create the 'name' field within the Human class, the String has 'S' capitalized? I guess I'll find out later
@Bro, Your Teaching skills and the examples you use are phenomenal. I've learned from nothing to something, All thanks to these tutorials.
wubba lubba dub dub!
@PixelPickleWaffle
Ай бұрын
Jhinga lala hoo hoo
Awesome stuff! I’m learning C# through a book called C# players guide. It’s a very good book but your content is really solidifying some of the complex key terms
Perfect. Very well explained with a good example.
Omg you're awesome! I struggled with OOP for 2 weeks in class and you just made this so simple. Thank you!
@ashrafsiddiq968
3 ай бұрын
I couldn't agree more
Nice video bro!! you help to understand in a good way how objects works!!
You explained this so well thank you!
Bro you are the best im trying to understand what is object for hours and you just made it clear, thak you so much!
Simply great! Thanks a lot!
clear and smooth af, thank you
Great breakdown, thanks bro.
Very straightforward and relatable 👍
Great explanation, thanks again Bro
Thank's for tutorials.
Love you bro, youre the best
THANKS FOR THE KNOWLEDGE BRO
Bro are awesome. Been trying to figure OOP thinking it's rocket science but you have made it where even I can understand it. Actually I got a degree in rocket science but that doesn't make me a rocket scientist.
great video! easy to understand bro
Thanks for the video Bro.
thank you so much for this
Großartig!!
Best channel out there
Thanks man!
nice!
Wow!
Thanks Bro!
Thank Bro!
bladah bang bro yeyeyeyye!
very useful!
thanks bro
Thank you Bro!!!
Thank you
Nooooice
noice
Bro code awesome
👍🏻👍🏻👍🏻👍🏻👍🏻💯💯💯💯😍😍😍
Aww, geez
👍
actual gigachad coder
If I let coding make me nervous, then I can’t get schwifty
YOU ARE JUST WOWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
Wubba libba dub dub!
"Wubba Lubba dub dub"
w
Evereyone's first project: "Hello world" My first project: Creating a human being from scratch
done
Can you do a tutorial in C?
Thanks for the tutorial, but is there a faster/more intuitive way to define an object with all of its properties? It seems like defining many objects with many different properties would be very time consuming. I'm more familiar with Python, where it's as easy as calling the class with all of the desired values for the properties.
@katawaya8101
11 ай бұрын
Nevermind! The answer is in the next video: kzread.info/dash/bejne/lXWcypipic6ugLQ.html
can you create tutorial vids like this using WinUI 2 or 3 UI frameworks?
wubba lubba dub dub
I promote you to Dude! Thanks! Dude!!!🤣😂🤣😂
🗿
wubba lubba dubba
Wubba Lubba Dub Dub!!!
interaction
if i want ro have my veriables private what do i do then?
System this is a random coment to help Brintey Stasy
Normally I put a random comment down below but why is it considered insecure to make them public? what would be the preferred solution?
@Donny956
6 ай бұрын
Im assuming having a second page for classes, and you can make them public on that page and just call them in to where you are woeking.
@Fork0
5 ай бұрын
Maybe a bit late to reply. In this case it doesn't matter, but usually fields should never be set to public, because they could be modified from anywhere in the program without the possibility for a validation of the newly assigned value. Take age for example: if you set it to public, anyone can just set it to whatever... 20, 60, 0, -123456. And then if your application relies on the value of age, it will have terrible consequences for the logic. Where as if you make the age private and also make 2 methods - void SetAge(int age) and int GetAge(), you can then add all the validation you want inside the SetAge method and throw exceptions if someone tries to add ages that make no sense, and use GetAge to actually get the value. Later on in this series you will learn more about this, but this is called Encapsulation (basically protection of data) and in C# you don't even need to do it with methods, but you'll learn to do it with properties (which pretty much mimic/replace those two methods i mentioned above). And as an additional info - fields are usually used for the internal logic of classes, whereas properties are exposed with public to the rest of the application so that people can use them instead of the fields.
357
lesson check😇
Watching in 2024
random
random comment
random comment down below
Random comment = new Random(10,12); Here it is your random comment. Thank you for simplifying concepts and making everything way easier!
Thanks bro helped a lot. 🫡
Console.WriteLine("Random comment");
wubba lubba dub dub
@aziz-mv7qo
2 жыл бұрын
u forgot the "!" at the end