Getting Started with Visual Studio & C# .NET Tutorial : #Codegasm 1

Hey! Whats up Nerdgasm fans. Jerry here. AKA Barnacules. Now you know im a software developer, I’ve actually developed software for Microsoft for 15 years. Well needless to say, I’m no longer with Microsoft. If you’d like to know more about that, there is a video down in the description. But at this time in my life I’m going to be my own boss now and focus on my passions and that’s programming, and making videos for you guys! YouTube! Well, I get a lot of questions from you guys asking whats it take to become a developer, what language you could use, how long does it take what school do you have to go to, do you have to drive a certain car, who’s butt you have to kiss. I get a lot of questions… So I decided instead of responding to literally hundreds of emails. Which could take a lot of time. The faster route would be just to create a whole new video series that would just show you guys how to do it. So I introduce Codegasm. In this new series what im hoping to do is show you guys how to get
up and running quick and learn your first language so we’re not going to be
focusing on super technical things we’re not going to get into be theory of
processor architecture memory management polymorphism multiple inheritance, we’re
not going to talk about that okay, that’s the last you’re going to hear of it well I don’t know you might hear it once or twice more. But what I’m going to focus on in this series is quick little
modules to get you guys interested get you up and running and kind of learn how
programming works this is going to be a very very basic series. So if you already know how to program, especially in C# .NET, hey you may want to watch the video just for some
lol’s; and you’re welcome to do it. So guys sit tight in this first episode
I’m going to show you how to set up your development environment. For this series
we’re gonna be using Visual Studio 2013 Express. Express means you don’t have to
pay for it. we’ll get into that in a
minute. Because free is good. Especially when you don’t have a job. Too soon! Too soon! ♫ ♫ ♫ Hey whats up guys! Okay so this is the
format that we’re going to use for the series of videos; I’m basically screen
capturing a VM that I have set up that has Windows 8.1 on it and I’m going to walk
you through the steps of setting up your first development environment. So the
very first thing that you’re going to want to do is go to this link and it’s
down in the description you can just click on it and this is actually gonna
be where you go to get Visual Studio Express. I’m going to actually open up my Chrome
here and we’ll navigate out all right once your to this page you’re
gonna want to scroll down don’t get the web version don’t get for Windows this
is a little confusing because it’s for writing modern applications we want the
desktop version right here so go ahead and click download and if you want a
language pack you can select that over here; or you can download the installer that
will install from the web by clicking install now or like I did you can just
download the ISO and then you have it so that you can install it on as many
machines as you want. All right so you can see, I have the ISO sitting
on my desktop well if you have Windows 8.1 you can just double click the ISO to mount it. Alright so now we have the ISO open as a folder so we’re going to go ahead
and just install it by double-clicking the application here now I’m just going
to install it to the default location here so let’s go ahead and agree to the
terms and you can also join the Visual Studio Experience Program which will
send crashes and information to Microsoft to help them improve the
product. Ok let’s go and install. Now of course you’re going to get the UAC
dialogue if you have security configured for it by default so let’s go ahead and
click yes – that’s just an extra precaution if you ever wondered why
those boxes popped up it’s just to make sure that you know
that something’s trying to do an administrative task on the computer and
this is good because then if you run something malicious you have that one
last chance to stop and be like no I didn’t run that hit cancel all right so
let me give you guys a little bit of background on programming here. Hopefully you’re completely new to it
because I’m assuming that you don’t know anything about programming you haven’t
done anything before doesn’t mean you can learn a couple things if you already
know how to code so hang in there but we’re going to start with the basics. Now
visual studio is your dev environment like I was saying it’s basically your
really hopped up text editor for writing your code and when I say code what I’m
talking about is you actually write a kind of human readable language we’re
going to something called C sharp and the language determines the syntax
basically how you tell the computer what to do but then there’s another element that’s
built into Visual Studio called a compiler and what a compiler does is it
takes that human-readable text and converts into machine language now the language
we’re going to be using for this tutorial is C# .NET now they’re
actually different entity; C# is the language and .NET is the libraries
that the language uses to manipulate things on the computer now see you guys
know what I mean when I say library just think of a library, a library contains a
ton of books, well a library in programming contains a whole lot of
knowledge on how to do activities so if you want to do a certain thing you go
get a certain book from the library to learn it well same thing in computers
you want to do a certain thing you go get a specific library and it contains
that functionality and knowledge to carry out that task. All right hopefully I didn’t lose you
guys with all that so the whole idea with this editor is you go in, you create
your program and you basically build on operations. It’s just like tools; if you have a – if
you wanted to make a hammer right you would go and forge the head of the
hammer and then you would go create the handle for the hammer and then you bring
those two together and then you have a hammer and then you could use that
hammer to build something and then you can use that something that you built to
build something even bigger. Programming is like that. You start with small
elements and you keep building on them; until you get a big element. All right once this is done installing
I’m going to go ahead and show you guys some of the features show you around
Visual Studio a little bit and then we’re going to go ahead and jump right
into it and create our first program. All right well we now have Visual Studio
2013 installed successfully so we just go and click the launch button here. Once you get through the initial
dialogue starting it for the first time and you select your preferences you end up
at this screen right here; this is like the main hub when you start Visual
Studio. Now I want to urge you guys to do some exploring if you look over here in
these panes, there’s tons of links to talking about how to create things these
are some of these are high-level topics, some of them are low-level topics but there’s a
lot of information to be found starting from this point right here. Now we’re gonna be developing in C#
but this is a capable program. You can do Visual Basic, you can do C++ you can do
WPF, Windows form web development – you name it you can do it. So what we’re going to do to get started
is we’re going to create a new project over here under start, just click new project. Now you have lots of options right here;
what we want to do is go down to Visual C# because everything that I do in
this video series at least for now is going to be in C# .NET so we’re
going to say we want to create a Windows application. Now you notice there’s multiple
different templates all these templates are as different project types that
start out with the foundation already built for you; that way you don’t have to start from
dead scratch every time you create an application. Now the easiest type of
application to create is a console application, now console application is
just a text based application that runs from the command console. We’ll go ahead
and just give the application a name down here we’re going to go ahead and
call it ‘Test App 1 – Codegasm’ just like so we’ll go and just leave it in the
default folder now down here there’s some checkboxes one says create
directory for solution I like to leave that unchecked because
then it puts everything in one directory if you leave that checked, it puts the
solution which is like the main template file that brings everything together one directory up and then it creates
another sub-directory that contains everything else. All right we’re gonna go ahead
and click OK visual studio is now creating my test app project. Now before we go any
further I just want to demonstrate for people that don’t know what a console
application is. A console application is when you open up cmd.exe also known as
the command console it’s this window right here and it’s
basically DOS for a lack of a better explanation it pretty much is I mean
it’s just basically your little sub operating system from the command prompt
you can start things from here you can open things like notepad. If you want you can do things like look
at the files see look at all the files and all the directories I mean there’s a
whole bunch of commands. If you type “help”, you can get a list of most of the commands
that you can run from the command prompt. Basically this is just a place where you
run console applications. All right so now that’s established, let’s go
back to our program. Now the file that it opened if you look over here in the
little solution folder over here on the right you can see there’s a program.cs file. That’s our source code file that’s where all the code is going to go
for our program now you can create as many files you
want you can link those files together you can do all kinds of really advanced
things but because I want to get you guys jumped in really quick and get you
interested we’re going to ignore all that for now the only thing that matters
is program.cs All right so here we’re inside of program.cs you can see up above we have some using statements we have something
called a namespace we have something called a class and we have something
called a function so we’re gonna go ahead and just put some comments on
these guys this is namespace, this right here is a
class and you want to heavily comment your code you can see right here I’m
just using //¸ that’s basically the signature that tells the compiler ignore
this it’s just a comment and then you have the function. Now this function right here they otherwise known
as an entry point I’ll go ahead and just put that right here. This is basically where your program
starts when you run your program from the command line when you type the name
of your program and it runs this is where it starts this is the starting
point of everything now one quick thing to note is up here
you see all these like little using texts. What using means is that basically these
are namespaces each one of these little guys are namespaces in a namespace is
this thing right here basically what this is doing is
creating a namespace called test_app_1___… Codegasm – I know it’s not very pretty but you can call it
whatever you want we’ll call it Jerry’s cool app code, that’s my namespace
now everything between this opening bracket and that closing bracket
belongs to that namespace it’s just a way of grouping things together
basically similar with a class, a class contains functionality so the class
contains functions and variables things that you want to run to actually evoke a
certain response out of the computer and then inside and then you can see this
class right here this is called a scope by the way between this guy in this guy everything belongs to that class so
basically if I select all this that’s all in the class so the class
program contains a function called main that’s what you would say if you’re
talking all programmatically but at the end of the day for this example all we care about is
Main, Main is important so now the first thing that I want to do in our
little program here this little demonstration is I want to basically
print something to the screen I want to show the user something so to do that
you just typed up console now console is a class which contains functionality so
if I just push . you can see I get this thing called intellisense it pops up and
it shows me all of the properties and all of the functions basically
everything that’s publicly available for me to use under that class in this
particular case we want to call a function called right line and if you
want to put text inside of this you basically have to put everything in
quotes anything you put in quotes is just a literal string as far as that’s
concerned so if you don’t want to create storage for that like for instance I could do something
like this I can come up here and say I want to create a string object an object
is just another fancy name for class or structure depending and what you’re doing let’s say I want
to create a string I can say string Jerry string equals hello this is
Jerry’s string for example now i can take this variable right here
and they called a variable because obviously its variable you can put
anything you want into it that’s it’s type like for instance I can only put
strings on a string just like if I created a number otherwise known as an
integer I can only put a number in it no quotes
around it now you notice that each at the end of
each line I’m actually putting this little semicolon and the semicolon
basically just tells the compiler that ok i’m done with that operation that’s one complete operation so now
down here if i want to write that string to the console so that the user can see
it I can type in Jerry string just like that and then I ended again with the
semicolon and if I just run this application which you can hold ctrl and
press f5 to do or you can just come up here to debug and you can go to start
without debugging and i’ll explain debugging and without debugging later so
start without debugging now it’s compiling my application you can see
down in the in the output below and it pops up and says hello this is jerry
string now we just push the key and it just kills the application now I can
also come in here and just put whatever I want in here this is jerry just typing
random stuff to the screen through console.writeline like that now if i do that and i run the
application again I’ll just hit ctrl f5 that’s the shortcut you see it pops up and it shows that
string now the cool thing about using variables that allows you to keep all of
your fixed data at the top of your constant data at the top of the function
so it’s very very easy to manipulate in tune as you go it’s generally frowned upon to just put
strings into functions like this right here but again this isn’t a professional
tutorial I want to get you guys interested in programming so we’re just
going to do with the fastest way possible alright so I’ve cleared out the main
function now we’re going to do something a little more complicated now we want to
print something to the user and we want to get the user to respond back to that
and then do something with it so for this demo we’re just going to do
a console.writeline just like we did before and this time i’m going to say type a number any number just like that now what we need to do is we need to get
something back from the user so what we do is a Console.ReadKey
this will read a single key from the keyboard basically it will block your
program meaning it will stop execution your program until a key is pressed on
the keyboard now the thing is we need to store that
key somewhere because we want to do something with it so one cool thing about visual studio is
you can literally just hover your mouse over things you can see right here and
it gives you information on like what the functions take as input and what
they return meaning what you get back from that function when it finishes
executing so in this case the reed key function returns a console if you look
at returns a console key info object so we want to create one of those we want
to say console key info and we’ll just call it key info so the first the first thing that you
type here is what you’re trying to create and then here is your friendly
name that you want for that instance that you created because you might want
to create multiple instances if you wanted another one you can do a ‘ConsoleKeyInfo KeyInfo to for instance and then you would have two separate key info
objects so these are the name so anytime that
you define something like you want to define a variable you first say what
variable type you want then the name you want to give to that variable so you can
recall it use it later on and then what you want to put into that variable which
like for instance I could just create a key and feed it into it but in this case
I want to get it from the console and that’s why i call ‘ReadKey’ so now what that is going to do is read
the key in the key info so now this little key info guy right here after i press the key is going to
contain the key that i pressed so now i can do ‘Console.WriteLine’ did you type and then use these little
parentheses here and 0 this means i want to basically put
something I want to take a variable and replace that with it and then i put a
little comma right here and then after it now it wants what i want to replace that
with so for instance i’m going to do ‘keyInfo’ which is what we just gathered
before and you can see under ‘keyInfo’ and so there’s a couple sub parameters that you
can select otherwise known as properties and you can select the key you can
select the character that the key produced modifiers all the stuff all we
want is the key character and we want to do to string and that’ll basically
convert it to a string that will replace this right here now there’s a lot of complexity behind
what I’m doing here and there’s a lot of variation you can do that’s what
programming is all about you pretty much have infinite variability but i’m trying
to show you guys how to do something very very quickly now if i compile this program and hit
ctrl f5 to run it you’re gonna see it says type and number
any number so i’m going to type the number five you see it says did you type 5 it’s
because it took that number it’s stored it and that it gave me a string back and
replace that to show me the number that I fight now that’s a very very simple program
but I’ve shown you so far is how to easily write something to the screen how to get something back and then how
to use that now let’s take it to a little bit more of a complex program now
we want to add some logic and logic is basically just direction of the program
based on certain inputs it’s going to make certain decisions so now let’s do something conditionally
based on what i typed let’s say if you can do this whole thing if the key info
character is equal to a lowercase a then i’m going to create this remember
this is the scope so anytime that you do logic you can do if so you can do for is
you can do Wiles you can look these things up if you want these conditional
situations basically if this is met if this is equal to a then it’s going to
run the code between these two points otherwise it’s just going to jump over
it and keep going so I’m going to say if the key character
that I type is a which you know isn’t a number just for example is not a number
that’s what we’re doing here then I’m going to do a console.writeline and i’m
going to say that is not a number knock it off now just like that now what’s going to happen oh sorry and
I used he i commented this code out earlier but just let you know any time
you don’t want a piece of code to run but you still want to leave in the
program because you may want to bring it back later just use to two forward slashes alright
so now what’s going to happen if we run this program hit ctrl f5 it asks for a number I’m going to give it a number says did
you type 3 ok without that work now what’s going to
happen if i press a that’s not a number knock it off now but then it says did you type in a ok so
what happened here is when you type a it ran this code and then it came down here
and that coat it basically is top to bottom order and
then it skips the logic that doesn’t match and goes through the logic dust
hope this is making sense to you guys I don’t do a whole lot of teaching but
that’s one of the reasons why i want to try this series out as I think it would
be fun to basically walk you through step from the absolute ground I don’t
see a lot of tutorials doing that a lot of them assume that you have a lot of
basic programming experience now don’t be overwhelmed if you don’t
understand everything that’s going on right now just play around with it i
urge you you will learn a lot through trial and error ok so now we’re going to do is on this
condition here this little if block here I say if it equals a well if it equals a
I don’t want to run that block of code so i have a couple of options I can do something called an else else
is just what it is do something else do something else so that’s a lot else it’s alright so
what we’re going to do here now is if a is pressed it’s going to run this code else if a is
impressed and it’s any other character it’s gonna put that line of code so if we run this program again you see
a typo number it says oh did you type for perfect ok
now what happens if a type-a that’s not a number knock it off now notice it did
not print did you type this thing right here it skipped it now this is fundamentally
how programming works it’s just very very large blocks of
simple code the way that programming works in
general is that you have the Machine language and then you have a layer of
abstraction from that and then you have another layer of abstraction from that
and it basically keeps getting simpler and simpler in each one of those layers
groups together a bunch of constructs from the layer beneath it like let me
give you an example that’s probably wickedly overwhelming let’s just say go back to the hammer
analogy right the lowest level part of programming would be the metal that the
ham that the hammer is made out of in the wood that the handle is made out the
next level would be the Hammerhead itself forged and the handle itself the
next level would be combining those two things into a hammer well it’s easier to just pick up a
hammer and use it to do stuff than having to learn how to smelt the metal
and build the hammer and then use the hammer a language like C sharp has libraries
which I was telling you about a little bit earlier that are inside of these
namespaces these libraries contain those functionalities one of those may contain
the hammer so i can use the hammer i don’t have to
go build the hammer before I use it now to give you a little bit of a better
example you can create stuff called functions everything is a function basically in
programming you create a function the whole concept of a function as you run a
function you give it variables it does something and then it returns a
result that’s that’s how functions work so we’re going to create a quick
function here and we’ll just call this function print food to screen all those
things going to do inside of it i’m going to console that right line who
just like that and let’s put a little comment on it too if you do three slashes at the top of a
function it actually gives you this cool little template that you can type into
it it’s pretty awesome you should use it so now we’re just going to type hear
what the function does all this function does is print foo to the screen that’s it that’s all this function does
now that I’ve created this function i can come up here and just use it
anywhere I want to use it all I type is the name of the function
that’s it now I can run this i’m going to press a key oh you see it printed foo right there
because what happened in the program again top to bottom it asked for a number i
entered a number it printed foo screen because this function basically says go
run everything between this point at this point functions are just a really
good way of organizing and structuring your code now to build on it like I was
telling you earlier let’s create another function let’s call it let’s create a
function called print foo to screen 100 times alright so now inside of our print foo
a screen a hundred times we basically want to create something called a loop
and what a loop is, it basically tells the program that I want to run a certain
piece of code over and over and over again until a certain condition is met now since we want to actually loop a
hundred times because we want to print foo of the screen a hundred times we’re gonna actually use something
called a for loop now the way the for loop works is you type ‘for’ and then it
takes three inputs the first one is the counter basically this is going to be literally
a counter that each time through the loop we’re going to increment so i’m going to go ahead and create an
integer called counter and i’m going to be equal to 0 the next is the condition
that has to be met for the loop to continue as soon as this condition is no
longer met you you break out of the loop it stops running so for this case we want to say the
counter is less than or equal to 100 so as long as counter is that the number of
counter is less than or equal to 100 I want to keep running that code and then
the next thing is how much I want to increment counter so each time through the loop we want to
increment counter by one so i’m going to increment counter by putting two pluses
after it that means incremented by one now for argument’s sake if you want to
increment it more than one you use this in fact you say i want to set counter
equal to itself plus two for instance and then that would increment counter by
to each time through the loop but for this example we’re going plus plus ok so now we’re inside of the loop now
we could do a console.writeline food but we already have a function that does
that we created a function called print foo to screen so we’re going to go ahead and call
print foo to screen just like that so now if i run this program what’s
going to happen is you’re going to come down here it’s going to print type
number of any number you’re going to press a key then it’s
going to run a function called print foo to screen a hundred times basically
going to jump all the way down here and run this code and then each time through
the loop is going to call our other function that prints just one foo to
the screen which then we’ll jump up here and run this code and so this these
these are all these order of operations that are occurring and they also called
a stack because in programming what you do is you one function calls another
function calls another function calls another function and that’s how you get
that rich functionality at the very very top without having to know how to do
each and every little thing on the computer a good example of this would be
console.writeline if you look up here I’m saying console.writeline they give
it a string it prints to the console what you don’t see is behind the scenes
there are tons of functions being called inside of that function to set focus to
the console set the font print to the console create a new line all that stuff is being done by other
functions but you don’t need to know about that you just want to print a line of text
you call the higher level function right line it’s just like the hammer analogy
earlier you don’t need to know how to smelt the metal you don’t even want to
know how to build the hammer you just want to use the hammer and
that’s what these high level functions allow you to do in the.net framework alright so what’s gonna happen if we run
this program right now ctrl f5 on our press a key foo just printed a hundred
times and that’s because we created that function now let’s say I want the program to
start and I want that to happen immediately before anything else I can
take that cut it put it at the very top of the program all I did was move this function and now
when I run it what’s going to happen it’s going to print foo first before
asking me what number I want because it’s that top-down everything’s from the
top down alright so for this very first video I’m
trying to keep it as simple as possible hopefully didn’t go over anybody’s head
if I did feel free to send me questions over twitter i’m @Barnacules i’ll try
to answer as many as I can and I do urge you to go out and do research and look
for stuff I have a ton of links down in the video description to things like
msdn in libraries and pluralsight and places where you can actually go to
continue the education the goal of this video series is just
kind of give you that kickstart show you the early capabilities and how easy it
is to get started so that then you can go and build on that so now we have our program built here
right it’s it’s an interesting program that prints foo a whole bunch of times,
it asks you to type something, it responds to it so it gives you some very very basic
programming functionality so now if i want to run this program or let’s say I
want to give this program to somebody else to run what I want to do is come over here to
the properties window down here and you can see the project folder is listed
right here i’m going to go ahead and copy that project folder and I’m going
to open it up in windows here it is now you can see those are your program
files well now if you want to give the program and somebody else you have to go
in the bin folder now you can see by default up here i have it set as debug
that’s just there’s different ways to compile your application the default is
debug that’s my profile i’m using so I want to look for my program under debug well when I every time you build your
program it re-creates all of these files the one that you’re interested in is
this one that has application right here and it doesn’t have vs host on it so
this right here if i delete everything else i’ll just delete it oh I can’t delete it because visual
studios using that one currently but this is your program right there you can literally give that to somebody
you could send it to them they could run it and it would run your code so now if I open up a
console window right here i can type CD which means change the current directory
and i can right click and I can paste it now i’m going to go into that folder now if i type dir you can see there’s my
program right there so I want to run it so i’m going to
right click and say mark just want to type it in and i’m going to paste it
just type the name of my program will actually have to put quotes around it
because there are spaces and so run the program there is a ran from the command
I type my key, it exits and you’re right back at the command console do it again hit a key, and you’re out so now you have
this program right here test app one codegasm exe that’s your program we just created that that is the compiled code
so basically it took our human readable code right here and turned it into
machine language that you can give to somebody else that’s all otherwise known
as an ‘exe’ or an application and then they can run well guys there’s our first program
right there well i hope you enjoyed this first episode of Codegasm I had a lot
of fun sorry the video got a little long but it
turns out programming is kind of a kind of a hard thing but regardless had a lot
of fun doing it and I’d love to continue doing this series and you guys get to
decide that please vote with that like and dislike
button if this video becomes popular and gets a lot of comments and a lot of
views i’m going to continue to make the series because I really do enjoy
programming I love sharing with you guys again this wasn’t designed to be like a
professional tutorial this isn’t a college class this is about me showing you just very
very simple ways to get up and running with some simple programming methods
that hopefully get you interested enough that you want more and you want more you
want more you go go search those links down in the description there’s lots of
good information out there for you guys to continue the education and keep an
eye out for more episodes of you guys enjoyed this now if you made it to the end of this
video I want you to leaves a word down in the comment that word is going to be
stay puft yeah the marshmallow guy I you guys leaving that the common it
helps me realize how many people are actually staying engaged throughout the
entire video and it helps me to know future videos need to be shorter and I
need to cut more stuff out generally i don’t go this long on a video but I felt
it was necessary to give you the basics on what a function is how to have a
function call another function and basically how to get input from the user
and use that input for something those are very very basic concepts and
there’s a lot of stuff i missed in this video guys I know this there’s I mean
literally programing is infinitely definable I mean you can
do anything i just want to give you guys a little taste so that you can see that
it doesn’t take hours and weeks and days to write an application it doesn’t it
depends on the application so guys I hope you take what I taught
you in this like small tiny little lesson and go build on it and i would
love to hear down in the comments what kind of variation you guys do on this i
want to see if you guys take this program to the next level I would love
to see how this influences you all right guys want to wrap up this first episode
of Codegasm had a lot of fun hope you did and until next time! ♫ ♫ ♫

Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,


Leave a Reply

Your email address will not be published. Required fields are marked *