Apr 22, 2025
C# (C-Sharp) is an extremely versatile programming language and is used as the driving code in a large number of applications including Unity for game design! This tutorial takes you through everything you need to know from downloading and installing the IDE (Integrated development environment) software from Microsoft called Visual Studio, to actually creating your first project and writing code!
We go through the main set up of the programming space, and show how to write data outputs to the console window, how to process and manipulate data using a variety of variables, and we show a number of different data types and discuss the applications and common use scenarios for each! Then we also show how to receive user inputs and store them in variables to use in our functions!
This is the first C# tutorial on this channel and I will start mixing these in with the other software tutorials we do going forward!
If you did enjoy this content or found it useful be sure to leave a like and subscribe to channel for more great content like this, and be sure to check out the channels for hundreds of useful tutorials!
Thanks for watching and good luck with your code!
what's going on guys welcome back to the
channel and today's video is going to be
an absolute beginner crash course in
c-sharp
[Music]
so to get started with c-sharp you're
going to want to install an ide in
integrated development environment and
the one i'll be using for this tutorial
series and i really recommend this one
is microsoft visual studio to get to it
just google visual studio download take
the link that'll take you to
microsoft.com and for
this installation you can either
download visual studio make sure you
grab community edition so you don't have
to pay for it it's totally free or you
can just hit this download visual studio
with net
if you do do the community download then
there's going to be a whole bunch of
options and you have to select some
things to make sure you get the right
type after you download visual studio
it's going to ask you what kind of
install you want and just make sure you
select the one that says dotnet
framework because that's what we'll be
using for c-sharp so once you have it
downloaded and installed you're gonna um
click on visual studio to get to open in
the just create a new project it gives
you all these options because visual
studio has like a hundred gigabytes
worth of plugins and different
applications you can run through it
but what we're going to be using is
console app with net framework so
there are there are so many options that
there's actually even two called console
application so make sure you grab the
one with net framework so that you can
follow along in this tutorial so hit
next give it a name we'll call this c
sharp
crash course um call it whatever you
want
and just hit create and what you're
going to notice once it loads up is
there's a little bit of pre-populated
code and you're going to see it says
using system and then a whole bunch of
add-ins after that
don't worry about these too much they're
essentially modules accessing things
inside of your computer so that the code
can run just leave it as is it needs to
be there but you don't really need to
know what it means for this tutorial and
then kind of the same with this solution
explorer over on the right
there's a whole bunch of things in there
properties references as we get more
into c-sharp we'll talk about what a lot
of those do but all you really need to
recognize for today is this c-sharp file
is given the same name you just gave
your project and you'll notice over here
on the left your namespace is also the
name of the project you just gave it
and this auto-populated class is really
just a location to put functional code
inside of it we'll really nail down a
description as we get more into the
tutorials but i just want to get you
guys programming as fast as possible and
then this static void main is a method
and a function where you're going to put
code as well but all you really need to
know for now is every time there's an
open and closed curly brackets that's
essentially the start of and end of a
code module and for getting started you
want to just put all of the functional
code inside of your main function you'll
notice the indentation is going to be
pretty much automatic for you so you
don't have to worry about syntax just
make sure it's inside the curly brackets
underneath static void main
and we'll write all of our code uh for
this tutorial inside of main okay
so the very first thing i want to do is
just get something displayed on the
console um if this is the first
programming language that you've ever
seen and somehow the first tutorial that
you've ever watched welcome and uh be
sure to like and subscribe for more
content but um you're probably familiar
with the fact the first program that
people always write is basically a hello
world program where they just print
hello world onto the screen
that's kind of boring so
we'll
instead of writing hello world we'll
write like what is
freaking up because that's way cooler
but i want to talk about this line of
code because there's a few things going
on here c-sharp specific
that we should really discuss so console
is how you address the window that's
going to pop up it's
the console is sort of referred to as
like the command window
if you're completely unfamiliar with
computers a console window is basically
the lowest level just simple display
that you can get out of your computer
there's not a lot going on it's black
and white typically it's just plain text
and so
console.writeline is all you need to put
in to get something to display on a
window when you run your program
but what you'll see so
console.writeline
and then open parentheses close
parentheses and then any text that you
put inside of quotation marks is going
to display on the screen and then make
sure anytime you have a line so this is
basically like a
a little executable it's an instruction
anytime you want to end an instruction
you need to make sure you put a
semicolon at the end of the line you're
going to get errors if you don't put
those in c sharp in in visual studio is
pretty good about helping you debug and
troubleshoot errors so if you forget a
semicolon a lot of times you'll get a
little error pop-up that says like
semicolon expected
you're going to forget about semicolons
people who've been programming for years
forget semicolons so don't worry about
it just try to keep that in mind
but so this is all we need to display
something on the screen but what you'll
see if i go up here and i hit start and
it's going to do something called
compiling
which is making sure your code is valid
and that's going to run but what you saw
there maybe you didn't
the the console pops up
just for like one scan of the computer
and then it goes away right away because
it's executing the code and then it's it
as far as it can tell it's done so what
we need to do is just put kind of a
break in this code by adding
console.read
and then we'll just do open and close
parentheses and then semicolon
and now when we run this i'll talk a
little bit about what that does
okay we get our text what is freaking up
that's sweet um so that's cool that's
basically our hello world program and
what it's doing right now you can see
the blinking inside of our console
window it's waiting for some sort of
text so i type whatever in here and then
when i hit enter it's gonna execute and
then read that line and that's when the
window closes
so we used this read line to add a break
to the programming but this is super
useful um anytime you want to slow down
a program and understand where it is at
the moment you just hit um you put a
console.readline in there and that'll
put a break in your programming
okay so that's sweet that's your first
function you've
downloaded visual studio and gotten
programming in like five minutes so
great job let's go to the next thing
let's start doing something kind of cool
a lot of tutorials will stop right there
and be like oh you learned visual studio
like uh you learned c sharp um let's
actually do something um useful so
i wanna talk real quick i'm going to
copy this console right line and we're
going to change the text but i want to
talk a little bit about the order it
goes in so i'm going to put like
three different fruits in here so that
you can see
um apple banana and then orange so
hopefully if you're familiar with
english and how we read in um you know
society we go left to right and top to
bottom and that's how c executes as well
so if i run this
you'll see apple first banana second
orange third so order matters and what i
mean by that is like if i'm to gonna
copy orange and move it up to the top
and then i run this
you're going to see orange before apple
and banana now so this order is is also
how it's going to execute so if you ever
write code where like something
happening down here needs to see
something has completed up here
order's really important it's going to
give you an error if you try to like
reference a variable that doesn't get
created until later in your program
that's kind of a universal truth of
programming so even if you learn other
languages if you learn python it's
exactly the same java it doesn't matter
if you try to reference a variable
on a line before you have
instantiated called defined whatever the
verbage of that language is if you
haven't created a variable you're not
going to be able to use it yet
so that's cool
we've written multiple lines of code
we've got a break in there so that we
can read about it but
let's let's start using variables i just
referenced variables just talking about
them and that's a super important thing
in all programming especially c sharp
to use variables is going to give you
some flexibility so let's say
you wanted to create a little mad libs
that's your name is pete
your
age is 25
and then we'll say third line
but next year
you will be
26 okay like yeah i can enter these
manually but that's not a very robust
program what would be a lot better is if
i had a variable for my name so we'll
make to make a variable you enter the
data type and we'll talk a little bit
about data types in a second
but name is gonna be a string so you
type in the word string and then you
type the name the name of your variable
which in this case is going to be name
and then you give it an initial value so
for a string we'll say name is going to
be equal to p and make sure you've got
your semicolon and then we will save for
age but age is going to be a whole
number so that's integer which is just
int in c-sharp and then we'll say age
and that's equal to and you don't need
quotations when you're doing integers
it's going to recognize the number
format okay
so now
instead of your name is pete we're gonna
say your name is space and then we're
going to use this plus sign which is um
it's technically addition but in string
terms this is called concatenation
and so we're basically saying your name
is plus and then the name of the
variable we gave it so we don't have to
type in the whole string name equal pete
we just say name and then it's the exact
same thing for age and this is one
difference between like python and c
sharp and c plus plus in c sharp it can
concatenate a string with a uh integer
or decimal value just by um it's able to
convert that it's able to handle that
internally if this was python you'd have
to do a string conversion so that you're
only dealing with strings
you can leave this in here just as an
integer but then this is a super cool
thing now
in the middle of our program we can just
say
age equals
the previous value of age plus one and
now we can say right here next year you
will be plus age and this is going to
get do basically exactly what we need it
to do it's always going to give you the
value and see i already forgot semicolon
this is always going to give you a value
saying next year you will be your age
plus one and you could make this a new
variable you could say like new age
equals age plus one you'd have to do the
whole gambit
just like this but
because order matters we can have it
work both ways we can just say age
equals age plus one and so this is going
to tell us we're 25 and then it's going
to add one to it and then next year
you'll be 26.
so if i go ahead and run this
and you run yours
um you're going to see your name is pete
your age is 25 next year will be 26.
okay let's do someone else let's say
your name is jack and you're
27.
okay so
all i did was change two values and
right away the whole thing updates to be
correct your name's jack 27 next year
will be 28
so that's the power of variables and
this is kind of a silly example because
there's not really a value in madlibs
but
in general anytime you store value in a
variable it's because you want to keep
using it you want to manipulate it
throughout your program
and it's a lot easier to store that
somewhere than have to keep in mind what
it was and hard code it
so that's super useful
that's kind of a brief introduction to
variables but let's say we want this to
be a little more intuitive and i don't
want to have to change these values
initially i want to ask the user for
input
because uh right now all we've all we're
really doing is providing output to the
system what we're going to do
is make it where we ask the user for
that name and for that age and this is
going to be great because essentially
the core of programming is get user
input process the input and then display
some output using the inputs that you
got so we're going to do all of that
inside this function in just a few
minutes
so
instead of
instead of just doing this string name
equals and then
just entering a value what we're gonna
do
is give them some instructions so we'll
use this console.writeline
and we'll say
parentheses
enter your name and we'll put that on
one line
and then we'll go ahead and close that
semicolon and now what we're going to do
is we're going to use and you've
actually already seen the
console.readline function
because we've used it before
make sure you get your indentations
correct
but what we do here is we say string
name equals and instead of giving an
initial value
what we're going to do is use
console.readline okay okay
so this is um
really cool now we're gonna say enter
your name and then the little blinker
the on the
you know thing signifying you're
entering text
is just gonna sit there until the user
types in their name and hits enter and
we're going to take whatever the user
entered and we're going to store it in a
variable called name that we'll then use
later on
so this is an important point here read
line is always going to take whatever
was written in as a string so if the
next thing we want to do i'm going to go
ahead and copy this but we're going to
change it to age
so right line enter your and this time
we will say age now
it's still going to be int age equals
but we can't just take
console.readline i wish we could but we
have to convert it to an integer because
it's coming in as a string and that's
why you're going to get like a red
squiggly line if you just leave it like
this because it's telling you it can't
just implicitly convert string to
integer it has to be told to convert it
fortunately that's a super easy function
in c sharp you just use convert
dot and then this in particular we're
going to an integer and so the the
function is 2 in 32 it's 32 because of
how many um
booleans technically in binary that
are used in an integer value you don't
have to worry about that you just have
to know it's 2in32
and then put that console.readline that
whole block of code put it inside its
own set of parentheses
and now it's the user is not going to
notice any difference between entering
their name and entering their age
it's just the code now knows to handle
that as an integer and then everything
else is going to work just fine so let's
go ahead and run this
let's say enter your name let's do pete
enter your age 25
your name is pete your age is 25 next
year you'll be 26. let's go ahead and
close it let's run again give it some
different values we're jack we're 27.
your name's jack you're 27 next year
it'll be 28. so just like that we've
created our first program our first
function our first
variables everything
inside of 15 minutes and hopefully you
understand where all this code is coming
from i know we haven't covered some of
the concepts of like structure of the
project structure of the file
but you're already able to pull a
variety of information in from users
manipulate it inside of your program and
then output data based on what you got
so this is a
crazy useful speed tutorial you learn a
lot of concepts right here in 15 minutes
i'll touch on one more thing before we
end this initial tutorial because
you've seen integers and you've seen
strings and we didn't really talk a ton
about them we basically just said
integers are whole numbers like in age
and string is any combination of text
but let's just talk briefly about two
things so first adding comments to code
in python i just used forward slashes
but there you do two backslashes and you
can type
whatever you want after that two forward
slashes is going to mean whatever else
is on that wrong on that line of code
isn't going to get executed they're just
notes for the programmer they live
inside of the function
so
everything i'm about to put underneath
here is just for our data type
discussion it's not really useful code
but this is how you do comments okay
so that's a super useful general um
piece about c sharp you should know and
we've already seen that integers are
basically any whole number like a
hundred or a hundred and twenty
um we've already seen that strings are
basically any text so
you could have
names or
i don't know other text or other things
okay but those are probably the two most
common ones you'll see
but a few others that really pop up a
lot in programming are
a double so i'll talk briefly about
there's a variety of ways to have
decimal point
values
and they could be in double
float or what's called decimal format
and i'm not going to go too into each of
them just know that it kind of is like
how precise do you need it float
technically speaking is the least
precise decimal is technically the most
i believe but just in general i always
use double for
decimal points so basically if you have
a number like money like you want to be
really accurate with money
so someone owes you 345 dollars and 35
cents i would always put that in a
double okay that's just another really
common variable
one that maybe you're not used to if you
don't do a lot of programming or you
haven't in the past is what's considered
a boolean but if you think of all the
scenarios in code where you have an on
off or a true false
yes no type scenario where you're just
checking if something is or is not
active this is also sometimes called
discrete points or digital points um
those are just all different names for
it but the variable type that you're
going to use the data type is boolean
and so boolean which i'll say is gonna
be true false can only have two values
true like that
or
false like that and it it's a super
useful thing in coding
it's way easier than creating an integer
and then checking every time you want to
reference it if it's equal to a zero or
a one or something like that or a string
and checking if it's equal to the text
true or the text false just use this
type of variable it's super critical in
programming and you're really going to
want to get familiar with booleans
um one more that's a little bit less
common is a character and so this is
like a single letter or a single number
that you wanted to put into a variable
of exactly space one but it could be a
varying character
so you could think of like a grade um
like a b c d f um in the in the grade
system and you actually use single
quotations for these ones so you could
put an a here it could be lower it could
be upper it could be a number um
but a character is only going to be able
to house one
character and if you put multiple in
it's going to give you an error so
that's character you won't see that one
as much but it is nice to know that it's
out there there are some other data
types that will probably crop up as we
do more and more of these tutorials but
for now those are the most common ones
that are going to pop up in your
tutorials
in your programs
but in general this is really a
20-minute crash course that should give
you a ton of concepts that are going to
get used in c-sharp all the time i hope
you found it useful if you did please
consider subscribing the channel liking
the video helps me out a ton if there's
something specific you want to see in a
future video be sure to let me know
about in the comments below i'll get
back to you as soon as possible and it
might even make that concept into a
video so thank you so much for your
support good luck with your code and
thanks for watching thanks bye