Тёмный
No video :(

C# enums 🪐 

Bro Code
Подписаться 2,1 млн
Просмотров 70 тыс.
50% 1

C# enums tutorial example explained
#C# #enum #tutorial
using System;
namespace MyFirstProgram
{
class Program
{
static void Main(string[] args)
{
// enums = special "class" that contains a set of named integer constants.
// Use enums when you have values that you know will not change,
// To get the integer value from an item, you must explicitly convert to an int
// name = integer
//Console.WriteLine(Planets.Mercury + " is planet #" + (int)Planets.Mercury);
//Console.WriteLine(Planets.Pluto + " is planet #" + (int)Planets.Pluto);
String name = PlanetRadius.Earth.ToString();
int radius = (int)PlanetRadius.Earth;
double volume = Volume(PlanetRadius.Earth);
Console.WriteLine("planet: " + name);
Console.WriteLine("radius: " + radius +"km");
Console.WriteLine("volume: " + volume +"km^3");
Console.ReadKey();
}
public static double Volume(PlanetRadius radius)
{
double volume = (4.0 / 3.0) * Math.PI * Math.Pow((int)radius, 3);
return volume;
}
}
enum Planets
{
Mercury = 1,
Venus = 2,
Earth = 3,
Mars = 4,
Jupiter = 5,
Saturn = 6,
Uranus = 7,
Neptune = 8,
Pluto = 9
}
enum PlanetRadius
{
Mercury = 2439,
Venus = 6051,
Earth = 6371,
Mars = 3389,
Jupiter = 69911,
Saturn = 58232,
Uranus = 25362,
Neptune = 24622,
Pluto = 1188
}
}

Опубликовано:

 

5 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 73   
@BroCodez
@BroCodez 3 года назад
using System; namespace MyFirstProgram { class Program { static void Main(string[] args) { // enums = special "class" that contains a set of named integer constants. // Use enums when you have values that you know will not change, // To get the integer value from an item, you must explicitly convert to an int // name = integer //Console.WriteLine(Planets.Mercury + " is planet #" + (int)Planets.Mercury); //Console.WriteLine(Planets.Pluto + " is planet #" + (int)Planets.Pluto); String name = PlanetRadius.Earth.ToString(); int radius = (int)PlanetRadius.Earth; double volume = Volume(PlanetRadius.Earth); Console.WriteLine("planet: " + name); Console.WriteLine("radius: " + radius +"km"); Console.WriteLine("volume: " + volume +"km^3"); Console.ReadKey(); } public static double Volume(PlanetRadius radius) { double volume = (4.0 / 3.0) * Math.PI * Math.Pow((int)radius, 3); return volume; } } enum Planets { Mercury = 1, Venus = 2, Earth = 3, Mars = 4, Jupiter = 5, Saturn = 6, Uranus = 7, Neptune = 8, Pluto = 9 } enum PlanetRadius { Mercury = 2439, Venus = 6051, Earth = 6371, Mars = 3389, Jupiter = 69911, Saturn = 58232, Uranus = 25362, Neptune = 24622, Pluto = 1188 } }
@girlkun7518
@girlkun7518 3 года назад
Hi! Could you make a video about topic "How to handle 2 keys pressed simultaneously in java"? Please... I'm Vietnamese and I'm really looking forward to this
@Wojbest_YT
@Wojbest_YT 6 месяцев назад
nerds about to be like " 🤓um actually Pluto isn't a planet🤓"
@whatdawhatgaming
@whatdawhatgaming 2 года назад
This is the best explanation of an enum I've come across. I knew exactly what is ACTUALLY was within the first 20 seconds. "A special type of class that contains a set of named integer constants." Literally a perfect explanation for me.
@jamiebertrand2669
@jamiebertrand2669 2 года назад
This helped a lot! I learned more in your 7 minute video than a 2 hour lecture!
@Iz_moe
@Iz_moe 2 года назад
"Pluto is a planet" -Jerry Smith
@BroCodez
@BroCodez 2 года назад
Pluto is a planet
@user-or6mz4gy6i
@user-or6mz4gy6i 6 месяцев назад
I really loved how you casually listed the planets radius. I don't know if it was really from memory but if it was you deserve other props here in addition to your programming skill. By the way, are Enums a special type of class or struct. They felt closer to the second to me. Thanks!
@user-or6mz4gy6i
@user-or6mz4gy6i 6 месяцев назад
I have my answer. As structs, enums are value types and stored in the stack. They they feel closer to structs. But if you change "special type of class" by "special type of data structure" it is still valid. Thanks!
@mttzern5457
@mttzern5457 2 года назад
Hands down the best c# explanations there is in regards to value for time spent - much appreciated!!
@NotTheHeroStudios
@NotTheHeroStudios Год назад
I got so hyped when you put Pluto on that list.
@atan6730
@atan6730 3 года назад
Pluto is not a planet, ruined my immersion.... Nice explaining of ENUMs btw, keep up the good work ^^
@SoDamnMetal
@SoDamnMetal 2 года назад
Oh you're one of "those" guys huh? 🙄
@mysteriousmop7686
@mysteriousmop7686 Год назад
if (joke) { return funny; } else { return !funny; }
@kusion7474
@kusion7474 9 месяцев назад
@@mysteriousmop7686”funny”
@ranjanadissanayaka5390
@ranjanadissanayaka5390 5 месяцев назад
I was really curious about Enum. Thanks for the video Sir. 😀
@rolfvanderbijl
@rolfvanderbijl 2 года назад
Great tutorial, clear, good examples and me is finally understanding why what I wanted to try didn't work. Thanks a lot!
@gameprogramming6550
@gameprogramming6550 Год назад
I have watched your almost all c# videos playlist. Thanks for the great content !!
@nav3622
@nav3622 2 года назад
I love you. You have helped me study for my midterms. I hope you get lots of happiness and success.
@deepbule3517
@deepbule3517 2 года назад
very clear and helpful. Thank you!
@tymofii4718
@tymofii4718 Год назад
Amazing Explanation and super quick. Didnt need to speed it up like most tutorials
@urmomlolgottem
@urmomlolgottem 6 месяцев назад
The sequels feel a bit empty but I will still watch them and enjoy the acting performances. I felt the last movie could have panned out in a more interesting way but I'm glad we got Kylo Ren ❤
@boyar3033
@boyar3033 Год назад
My go to man for c#
@spartanranger
@spartanranger 3 года назад
Thanks for the video Bro.
@ozknowledge4159
@ozknowledge4159 2 года назад
superbe Thank you for this great tutorial
@fredrikandersson1538
@fredrikandersson1538 Месяц назад
Solid ty
@chrisp2639
@chrisp2639 Год назад
good stuff
@McPatoo
@McPatoo 10 месяцев назад
Helpful as always :) gigachad bro
@Cheboksarov
@Cheboksarov Год назад
Познавательно.
@eerice704
@eerice704 Год назад
Justice for Pluto ✊🫡
@w9xv_433
@w9xv_433 Год назад
🐐fr
@mahdialaaaldine
@mahdialaaaldine Год назад
Thank you !
@TIPSFIN
@TIPSFIN Год назад
i have a question. If i remove the points and zeroes before the number 4 and number 3 in my method, why does it fuck up my answer? This works: public static double CalculateBallVolume(double aRadius) { double volume = (4.0 / 3.0) * Math.PI * Math.Pow(aRadius,3); return volume; } This gives me a different answer that is not the volume of a sphere: public static double CalculateBallVolume(double aRadius) { double volume = (4 / 3) * Math.PI * Math.Pow(aRadius,3); return volume; } You can try it out yourself. (4.0 / 3.0) and (4 / 3) give different answers for some reason.
@ajlakanen
@ajlakanen 6 месяцев назад
When both of the numbers are integers, the result will also be an integer. When at least one of the numbers is a double, the result will be double. Technically that's something called "operator overloading" -- that is, the division operator works a bit differently based on the types of the operands.
@alexgolomb363
@alexgolomb363 Год назад
Thanks bro
@timoneri8812
@timoneri8812 2 года назад
📡👽🛸 Thank you! Very Clear! ;)
@Commenter339
@Commenter339 Год назад
great vid
@harmony4537
@harmony4537 Год назад
you are the best
@titkosaaron4067
@titkosaaron4067 2 года назад
Great video, thanks!
@amplifiedge
@amplifiedge Год назад
thank you bro!
@zachdavis6624
@zachdavis6624 2 года назад
This was helpful! thanks.
@nguyencanh8369
@nguyencanh8369 Год назад
thanks
@Bear-nr9jo
@Bear-nr9jo 3 года назад
Bro your channel is lit my guy
@erikseberozvoj
@erikseberozvoj Год назад
Great video bro! keep it up
@xwoken
@xwoken 3 года назад
nice
@Anonymationsthecoolanimator
@Anonymationsthecoolanimator 3 года назад
Java and C# enums are so much similar that it is confusing me.
@dakar_84
@dakar_84 3 года назад
C# really similar to Java itself
@zachdavis6624
@zachdavis6624 2 года назад
I was a little confused by the way you passed in radius there at the end, but that might just be my inexperience in C#
@AliTahreiSh
@AliTahreiSh 2 года назад
What is the difference between Enum and Dictionary?
@emilyalbert3366
@emilyalbert3366 9 месяцев назад
you can update, add, and change values in a dictionary
@satyamshankar5459
@satyamshankar5459 3 года назад
great!
@zachnewby4739
@zachnewby4739 Год назад
If you are having trouble, enums can't be member variables, meaning they can't go inside other classes.
@linglingzhang8583
@linglingzhang8583 3 года назад
i really like the way how you teach, if you are familiar with java framework, and make a tutorial for that, that will be great.!
@jessiebessie3616
@jessiebessie3616 Год назад
So can we use Planet enum to fetch corresponding values in Planetradius enum directly?
@abdurahmon9926
@abdurahmon9926 Год назад
real gigachad
@giacomorinaldi
@giacomorinaldi Год назад
hello Bro, i have one question: why you wrote in this way the method ? public static double Volume(PlanetRadius anyvariable) { double volume = (4.0 / 3.0) * Math.PI * Math.Pow((int)anyvariable, 3); return volume; } i dont understand why you put PlanetRadius in the method. please could you help me ?
@fruitfunfitness3584
@fruitfunfitness3584 Год назад
I was surprised that your double ended up with a non integer value when it was calculated with an int, without casting the int into double. I suppose Math.pow is casting it.
3 года назад
Thanks Bro!
@nulzn8691
@nulzn8691 Год назад
I though it was going to be a bigger debate about whether Pluto is a planet or not 😅
@asapboy1895
@asapboy1895 3 года назад
This can be ran in java right? (Nice Work btw Bro)
@Lonchanick
@Lonchanick Год назад
I find barely useful the enums utility ... that could be done with a class right?
@triodit
@triodit Год назад
if pluto is a planet, then there are over 30,000 planets in the solar system....
@kvelez
@kvelez 10 месяцев назад
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp1 { public class Program { static void Main(string[] args) { Console.WriteLine($"{Planets.Pluto} is the #{(int)Planets.Pluto}"); Console.WriteLine($"{(int)Radius.Uranus}"); } } enum Planets { Mercury = 1, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Nepture, Pluto, } enum Radius { Mercury = 1453, Venus = 56443, Earth = 363, Mars = 7463, Jupiter = 64532, Saturn = 3442, Uranus = 35442, Nepture = 76393, Pluto = 32408, } }
@davidtummers8310
@davidtummers8310 6 месяцев назад
WROOOOOONG! Pluto isn't a Planet anymore (sadly😢)
@whitedinamo
@whitedinamo 2 года назад
lesson check😇
@aditya_asundi
@aditya_asundi 3 года назад
first
@SpecsNStats
@SpecsNStats 2 года назад
a random comment
@lotar1228
@lotar1228 Год назад
i know that i shouldn't be focusing on this but pluto is not a planet
@MW-ow8zh
@MW-ow8zh 8 месяцев назад
bro said pluto is a planet
@shaikhparwez7276
@shaikhparwez7276 6 месяцев назад
why u have pluto in there UNSUBSCRIBED !
@triton5457
@triton5457 2 года назад
salad 🥗
@welitonkira2830
@welitonkira2830 Год назад
Thank you!
Далее
C# generics ⁉️
5:33
Просмотров 74 тыс.
C# Lists 📃
6:46
Просмотров 102 тыс.
C# Enums for beginners
8:34
Просмотров 8 тыс.
C# interfaces 🐟
5:38
Просмотров 129 тыс.
C# multithreading 🧶
6:59
Просмотров 153 тыс.
Premature Optimization
12:39
Просмотров 802 тыс.
C# polymorphism 🎭
5:11
Просмотров 79 тыс.