How to Program in C# - Methods (E06)
Вставка
- Опубліковано 15 вер 2024
- Let's learn how to re-use code with methods in C#!
► Check out Milanote for free: www.milanote.c...
● My Solution to the Challenge: bit.ly/3b4JVmJ
····················································································
❤️ Donate: www.paypal.com...
► Join Discord: / discord
● Website: brackeys.com/
● Twitter: / brackeystweet
● Instagram: / brackeysteam
····················································································
► All content by Brackeys is 100% free. We believe that education should be available for everyone.
❤️ Donate: www.paypal.com...
····················································································
♪ "ES_Dress Code_Black - oomiee" by Epidemic Sound
I had done a 50 hour C# course and it didn't do me much, plus it cost 30$.
But your series of videos are so clear and simple that I am now even better than my friend whos been coding C# for 3 months! Thanks a lot Brackeys!
You can code for 3 months but still not know a lot of stuff. I have been coding with GoLang for year, I really like it, however I can barely put something from a http request into a database. Whilst python (I know for 4 years), I do not know how to do something like that. TLDR: good explation will really help your career and time really doesnt matter unless you are doing it 24/7
@@eclipsek0 bars
@@demonboi6930what
I feel bad to whoever sells you their course first. You obviously didn't credit them for the foundational knowledge which made this one so useful to you.
I think making a solar system simulator would be cool. This series is really helpful BTW.
i.imgur.com/TIPKdJ2.png I had to do something very similar to that in my highschool comp sci class and it was quite enjoyable getting it to finally work. I definitely messed up the numbers in the picture but you get the idea.
Kel that looks really good!
@@gamergreat9505 Thanks! I know these tutorials are specifically meant for Unity but if you do wanna learn these helped me A LOT with scripting and understanding the language: catlikecoding.com/unity/tutorials/
@@kel1836 nice
@@gamergreat9505 good luck and never give up!
The last two challenges I had to look up on the forum but I bloody got this one!!! Some trial and error and some seriously hard thinking went on but as an absolute beginner not just at C# but in the world of programming itself, I am very very proud of myself, the sense of achievement is immense, and I feel like with this challenge I've actually built a useful tool, amazing! Thank you so much brackeys!
very happy i did this challenge with no help!
here is my code :D
upitnik();
Console.ReadKey();
static void upitnik()
{
Console.WriteLine("Write a sentence: ");
string sentence = Console.ReadLine();
int wordCount = sentence.Split(' ').Length;
Console.WriteLine("The amount of words in this is " + wordCount);
}
i feel dumb xd
This was really beginner friendly! Also like that you didnt make this specific to Unity
Even after 3 years, your videos are super helpful. I did all your homeworks without looking up the solutions. Especially this one took me a bit, but then it suddenly clicked and after some modifications, it runs perfectly fine and it's not much code. :)
Brackeys: "so ill set the age to be between 10 and-..."
Why do I hear police sirens?
I scrolled down to the comments immediately after he said it.
theyre aliens
@Engine omar cringe, you dont know how to r/woooosh people
@Engine omar aha yes you got double wooshed
@@neutralz_8676 Well... not really but ok
Brackeys please make this series a long one, its very helpful and I cant thank you enough for all the knowledge you are giving for free. Thank you so much
This didint age long )=
brackey gone
He didn't do it for free because UA-cam pays him AND he had a sponsor. So... Not free.
its free for us though?@@JuanSumChninezeFue
and this guys comments 3 years old lol
This series has helped me so much thanks brackeys
heres a quick tip: just type cw and enter
insted of typing console.writeline(); to qucikly print
Thank you so much
doesn't work in my vs code
@@hikohiko9358 try typing cw and then pressing tab twice
So, a year and a half later I'm running trough the course and I must say they are still great!
This challenge had me a little stumped for a bit, but only because I was looking for the why.
Why would you use a method or function, when you can just as easily write it in main.
The answer is: just for practice. Ours is not to reason why, ours is to reason how.
Once you get past that the solution of the challenge is easy.
The practice is in separating which variable can get called where, why you can use the same definitions for variables over different methods/functions and
to help you practice organizing and cleaning up your code.
Hope that helps you solve it, before going to look at the forum and find the solution!
Wow, I started watching these, like, 2 days ago.
Didn't expect a new one _that_ soon.
Same, but keep in mind last episode was out 2 weeks ago
Oh, you think so?
Then just wait for the next episode to be posted
me too
The joy that i felt when i guessed that you were gonna say "return result" is absolutely overwhelming
This video is perfect. Really.
Even the way of promoting sponsor is great, it shows it at beginning and reminds you to check it out at the end.
I've never used any programming before but this series is amazing - I modified this tutorial so that the user was able to input their own numbers on command, so it works as a calculator of sorts. I know it's simple but if you'd have asked me a week ago I'd be clueless, so thank you so much :)
(also this is the first challenge I'm stumped on
Honestly, thank you very much for making these tutorials, you are the reason i finally pushed myself and started doing something! Also this is the last episode where i had a little bit of knowledge about the thing i was doing. Next time classes? wtf is that
Im really hyped to find out next time :D
Tak co, pochopils je? :DD
When you have 36 errors, write one letter, and all the errors are gone.
more like the ;
that what mostly happens to me
did it fix after you typed the c in static?
One night time a program for c Sharp and it give me a error and then when I checked I accidentally write it for c plus plus
Semicolon?
Looking forward to the next couple tutorials. Having trouble understanding how to utilize class modifiers and how to communicate between multiple scripts. Thanks for making these!
Thank you for this video! Easy to understand, good examples, no bs. Loved it!
For the solution, you could get really advanced and extend the "string" class so you can call WordCount() on any string anywhere in your project
public static class StringExtensions
{
public static int CountWords (this string s)
{
return s.Split(' ').Length;
}
}
Then you can just call it on a string like so:
"My String".WordCount();
- or on a string variable -
myString.WordCount();
woah ididnt know u could extend the string class
@@caiogamer2723 yeah man. You can extend any class that isn't Static
This would return 1 when using empty string
Btw string is not a class it a variable class is void and static etc.
Sunday is a very special day. Thank you Brackeys!
The quality of these videos are incredible!
I love these series! It definetly helped me A LOT when programing in Unity with C#. Most of the things are not the same but the logic is. Sorry if I have spelling mistakes. :/
13:46 I believe 5 % 2 --> remainder of 1 not 0.5
Awesome series though, keep it up!
Yep you're right..
Yes, don't know why he said .5 :P
@@Maggiethegsd It's a bit confusing tbh.. I don't blame him
Idk man
yeah, at least it doesnt mess up when ur trynna figure out if a number is even or not
grandma approved
@BRY_ 00 _LEW MIIIIIIIIIISSTEEEEEEEEEEER BEEEEAAAAST 6000!
This is OwO
I haven't seen that sticker in a long long time.....
our babushka!?
Hope this playlist won't take a *whole year* to complete!!
welp
@@yomama5029 :(
theres only one more episode dude
this aged well lmao
@@cybr69lol It did. The series ended with 'classes'.
Thanks for staying so consistently awesome with your videos!
bro just call it odd insted of uneven , btw thanks ur the first one i go to for a code tutorial
definitely the most confusing video yet (Parameters && return values), gonna take a while to get the hang of this one lol
(I don't mean confusing in a bad way btw)
I also think i didn't learn it
I can't get the logic behind its codes
if Brackeys didn't exist i wouldn't able to learn programming and Unity
in the quarantine
Thanks Brackeys
This is a good teaching series and it helps me understand C# and put it as my favorite programming language, :D.
One of the best channel about unity ever! 🤩🤩🤩
Hey Brackeys, are you going to bring up local functions? Those are methods that are inside other methods. Only the parent method can call them (really helps if that method is going to be the only caller/cleans up lambda's) and they are either static (ie, they cannot access anything inside the parent method/object) or not (can access anything inside parent method and object.) They can also be async or not along with being unsafe of not.
There is a specific word for what you have been describing - scope!
It's kinda an advanced stuff imo, and sometimes can make testing harder but yeah i like them too. Especially when i need Coroutine functionalities inside a method
Plz never stop with this series, thank you.
This was SUPER useful in my coding project, didnt know these existed and you saved me HOURS of time
You might not be an active channel anymore and will probaly never see this but you are still a life saver
So far u are the Best that makes my understand c#
Can't wait for next part, I really like your tutorials, I can understand them more than others
Even tho i have a lot of experience with C#, i still wanna dive back when i started learning C# (using my phone at school while the teacher explained stuff) by watching these videos.
omg I love you. This took me SO LONG to understand. I just didn't... but now I do ;)
These c# prorgramming tutorials are awesome. You're the best 😜👍
TNice tutorials is much more simple than I thought with you explaining it. Currently half way through and I feel like I know everytNice tutorialng already lmao
Dear Brackley,
If you are reading this please make a tutorial on "how to make a shop"
it would really help! Thanks
'Dear Brackley" wow.
Best turtorial's on yt no cap
Thank you for this video! I am taking computer science 1 at university right now and next weeks topic will be methods. Thank you for the primer!
Thank you for sponsoring my journey to learn c#.
I finally got the hang of this. I made two methods, one named MathQuiz, and then other named Print number. I put the MathQuiz method first in the line of order, so my program ran through that one first. PrintNumber was then, ran through shortly after. I know it's not much, but this really stumped me for a while.
😥 Brackeys is my most favourite youtube channel ever. I was going to take photo with you in brackeys studio some day. Good bye man! You really hit my heart as a teacher.
That Is useful in gambling LOL
I like your videos brackeys you are the first person who inspire me to starting game development
This video is worth to follow.... I'm learning from him how to make this kind of nice tutorials.
Am I the only one who was *OKAY* the whole series and just got *LOST* in this episode ?? AHAH it's sooo confusinggg!!!
No. I feel your pain.
@@MxrcellXD ahahah
Awesome videos! This has helped me tremendously on my coding journey!
for that challange you dont need to use methods, you can do int with only some variables like this :
static void Main(string[] args)
{
Console.WriteLine("Write the sentence");
string sentence = Console.ReadLine();
int numWords = Convert.ToInt32(sentence.Split().Length);
Console.WriteLine(numWords);
Console.ReadKey();
}
Yes. But this is a beginner friendly tutorial about METHODS. So he wants us to try using them even though you don't technically NEED to use them.
These video are so great! I really appreciate all the help you gave me!
Best course that I've done, I did some c plus plus on youtube in a 4h course but it was way too long and less entertaining than you!
Thank you so much brackeys!
Yeah well C++ is never really fun to learn
@@hoiblij6737 but i'm pretty sure brackeys would make it fun
@@noavr1308 i guess its in freecodecamp.org
@@sonnysarcia6947 yes hahaha
@@noavr1308 i'm changing my engine to unity and c# because my computer cant run unreal and that feels so bad for me because I have mastered the c++
Hi, Brackeys, imho, you should have mentioned that c# (latest standard) actually allows method definition inside other method body.
Anyway, your videos are great!)
I bet you can never find a better tutorial on C# on the whole internet, lokey sad he doesnt do this anymore
Happy Teacher's Day
YOU ARE HELPING US A LOT TO LEARN C# .....
I had to look at the solution to get this one and I don't think I could yet replicate this or apply it on my own. Love this tutorial though!
This guy explains it so well that even a 2 month old baby would understand what he says :)
Thank you so much for the guidance, I understand this fully well, I'm currently studyin programming for the first time and I find the basics so complicated XD
Best series ever. Nocap.
Ah, Methods
Something that YandereDev had never implemented in his "code" (If we can call it that already)
Not really code, more of like unreadable chaos
and also switch statements
@@Lena-qg8bd and for loops
@@Owen3H and if statements
@@Owen3H Not to mention having them all in one script that runs in every character in the game meaning they all have to be checked everytime
I didn't know this video existed! Thanks bro! Really grateful.
Hey Mr.brackeys I just wanna say
Keep up the good work
Thx for keeping it free
keep this great work up, im gonna get to watching this course once i have finished my java course
I'm enjoying your lessons, you make things very easy to understand. I'm waiting for lessons 7
I am just waiting for this series to be over and then I will watch all of those videos together
This series is really good it helps me a lot but I want to learn fast but these videos are only on sunday sadly. But still really good work please continue in this series.
this channel is very helpful. very thankful to this Brackeys
After i'm done with all the episodes of how to write C# , i will look at unity tutorials too :D
Your tutorials helped me a lot and i am thankful for that.
New Brackeys videoooooo! Day just got better!
This sponsor really good 👍👍 I really need this
Yo brackeys I'm trying to learn how to make games and I've wanted to make games ever since I was a kid. I wanna learn from one of the best so that I can become successful in my goal as I grow up. If you can reach out to me through something please do so.
Just wanted to add that
sentence.Count(char.IsLetter);
can count letters instead of words.
Nice video. But I have to make one really small correction in that there is a differnce between a method and a function. Still they behave exactly the same but a function is block of code you can call where a method is a function within a class. Thus a function doesn't need to be in a class, it can also just be within a namespace.
It is just a small detail and it doesn't change their functionality, but there is still this difference and some people online make a huge deal out of this.
Nice tutorial, even I can barely understand english! Keep up the good work!
Happy teacher's day...in India on September 5th we celebrate as teacher's day....and I want to wish you... Happy teacher's day ❤️🙏💐hope we'll meet someday....
Hey can u do a tutorial that turns ur game from the how to make a game tutorial series into a mobile game with touch control
CLYDE THEDOGE agreed
It is not difficult to do so. You just need to understand the basics of how to write code to detect Touch gestures. There are plenty of tutorials out there.
@@aarondelgado3421 oh u got any link?
Thank you so much!!! It did work and took less t
After this episode i felt like a pro programmer
lmaoo same
Pro-grammer
Brackeys: let's make an alien dating site!
Also Brackeys: int age = numberGen(10, 500);
Alien FBI: Put this creep on the probing list. 👽👮♂️
Yay! I Learned how make a bot that works for the scp foundation and automatically names scps and d class personnels using Methods! Thanks!
I didn't watch the video yet but you got a like
Please make a tutorial to the new Unity Multiplayer Engine.
That would be rly nice! : )
Functions have many functions but ideally one function should have only one function.
Anyways you explained the function of functions quite functionally.
Awesome! But will you please talk about *Refactoring* and how it saves you and your friends from brain cancer?
Respect to you for every video!
Thank you for the lesson! It was incredibly helpful. I have one question, though: what's the difference between methods and functions??
none, he said himself that it's just a different name that you could use
@@caiogamer2723 Thank you! I probably didn't notice. Not a native English speaker lol
@@wesleylima5723 neither am i
U are better than my teacher for real
damn dude, you've just made the best c# course
I spent so long trying to figure out the challenge and then realized you mentioned the split function at the end of the video 😭😭
something that could be very use full is to write this:
static void WriteLine (string Text)
{
Console.WriteLine(Text);
}
static void Write (string Text)
{
Console.Write(Text);
}
if you write that, instead of having to type:
Console.Write("insert something here");
you can type:
write ("insert something here);
did it in like 3min, so happy
For those familiar with other programming languages, a Method is simply known as a subroutine. Same idea and mostly the same implementation.
Thanks mate i was thinking it must be that but was so confused by the name 😂
tutorial on how to make saucy alien dating sim when?
hey so i didn't use .split method, i just counted amount of spaces in the sentence in function and that seemed to work well enough
void wordCounter(){
int counter = 1;
for (int i = 0; i < sentence.Length; i++)
{
if (sentence[i] == ' '){
counter += 1;
}
}
Console.Write(counter + " words");
}
sentence was declared as a global variable by the way
Even though I went to school and know most of this, I just come here for the wacky examples and just laugh a bit!
Nice job making this series it's great