Game Basics Installing Visual Studio and Intro to Programming
Hello everyone
I'm Lee Yeong-hoon, and I'm in charge of this C#-based object-oriented programming lecture
The course will cover
installing Visual Studio and programming basics,
data types and variables,
conditional statements and loops,
and functions and classes,
in that order
In this lesson, we will
install Visual Studio, an integrated development environment,
learn basic programming concepts,
and study C# fundamentals
Installing Visual Studio Printing Hello World
Today, we will install Visual Studio,
try simple coding,
and also discuss the overall
development process
Let's install Visual Studio from Google
Let's search
Visual Studio
There's version 2022,
so you can use this version
Even for Unity,
we're using their version 2022
So here, we see many things
And we have Community 2022
This is the free version
So let's use this
Over to this side,
we're seeing some downloads
All done
If it doesn't work, click here
Select Visual Studio Setup
Now we can install through
Visual Studio Installer
So let's continue installing
This may take a while
based on your internet speed
Let's wait a bit and continue
To install Visual Studio,
this Installer works like a launcher
Sao this has expansions
that we can add to Visual Studio
for our programming
Before we begin,
we need to check
this .NET Desktop Programming
And down here,
you'll see Game Development with Unity
Let's check this as well
So again, check for .Net Desktop
and also this Game Development
Check for these two
Here, we also have C++
If you're using Unreal,
you can also check this
Next, to bottom right,
click Install
This will download
all the necessary information
Now that this is done,
it will automatically open
We had this box ticked,
so that it opens right away
So now we have this
Create an account and log in
Then this will continue to be free
It's also free for the first month, with the trial version
For now, I will skip
and continue
So you can select
the theme that you like
I will keep the dark mode
Now, for the Visual Studio,
first, through the Visual Studio Installer,
Click on M for Modify
This allows us to add more features,
or remove any
You can untick the box
to remove it
That's how you manage these
Now that we no longer need the Installer,
I’ll go ahead and close it
Once that’s done, Visual Studio should open like this
You can see various options here
We’re going to create a new project,
so let’s click on that
ou’ll see a variety of templates,
but we won’t use all of them
Here, you’ll find the language options
We’ll select C#
Next, on the far right, you’ll see a format option
We’ll use the Console app
After selecting Console,
two options will appear
We’ll choose .NET Framework
Once that’s selected,
click the Next button
Now, we can configure our new project
This window shows
the project
and solution names
It’s important to understand
what a solution
and a project are
A solution is a broader concept,
and a project is
part of the solution
So basically,
if you’re only making one project,
you can use the same name
for both the solution and the project
But if you’re managing multiple projects
under one solution,
you can give them different names
Let’s create a project
to print Hello World
When people first learn coding,
printing Hello World
is usually the first thing they do
If you can do that, you’re already halfway there!
Let’s create a project
to print Hello World
For the solution name,
I’ll use Coding
That's it
Now, for the location
We’re talking about
where to save this project and solution
You can leave it as it is,
but I’ll go ahead and put it in a new folder
You’ll see
that I’ve created a folder called Project,
so I’ll save it there
After setting that,
click the Create button
You’ll see
the project being created
If you open the folder,
You’ll find that
a Hello World project folder
is created under
the Coding folder
There’s also a file named Coding.sln
This is the solution file
So here is the solution file,
and the Hello World project under it
That's how it works
Now that we understand the structure,
let’s open the Visual Studio project
Here,
you should see the Solution Explorer
If you don’t see it,
go to the top bar and click
on Window Layout Reset
Click on it,
and you'll see it
Now, in the Solution Explorer,
you’ll see “Coding” as the solution,
and below that,
the Hello World project
The file we’re working
with now is called Program.cs
Let’s go ahead and print Hello World
I know we’re still beginners, but here’s what we do
You’ll see the word Main
This is the function we’ll use
At Main, we have the curly braces
Inside the curly braces
is called the scope
I’ll call it a space for now,
because it occupies a space like so
You’ll see these scopes here as well
Inside this scope under Main,
you can automatically indent
by pressing the Tab key
Now, type this
Console
And a period
It will complete it for you
WriteLine
Press Tab to get this
And open a parenthesis
And add quotation marks
Let's type Hello World
There we have it
Let's save it
To save, use Ctrl+S
For saving all files,
you can use Ctrl+Shift+S
Both Ctrl+S and Ctrl+Shift+S
can save the file
This is our source file,
or a source code
This is where we write our codes
Let's run it
After saving,
look at the top for the button
Or if you look here, there is an option
called Build and Debug
When you build, you make the program ready to run
The build process
turns your source code
into an executable file
So, let’s try this
Let's try building it now
Click on Build, and the process will start
It's building
The build is complete,
and you’ll see a message saying, Build 1 succeeded
Then, there’s the Debug section
You’ll find options
to either to start debugging
or to start without debugging
You can use the shortcuts F5
or Ctrl+F5 to do these
It's the same thing here
This will start the program with debugging enabled
Let’s try running it with this
Here’s what happens
when you press Ctrl+F5
A black console window will open up
This window is called the console window
In the console, you should see
Hello World displayed
Now, let’s close the console window
This is how the structure is set up
In the code, there is a line that says using,
which means we are using
some system functionality
There’s also the term namespace,
which has name and space in its term, right?
It stands for creating a container or space for code
Let me explicate
Inside the namespace,
you will see the class Program
Hover over Program to see its details
Here at class,
the Program class is the only class here,
but in the upper part of the screen, you’ll notice
HelloWorld.Program written
So the meaning of this namespace
is that it holds a space,
and its keywords
that belong to that space
are part of the namespace
Now, let’s take a closer look
The Main function,
which we referred to earlier,
is where the program begins
The Main function is known as the entry point
of the C# application
Let me explain about application
Have you heard about app?
App stands for application
We're familiar with app
An application is referring
to a software application
When we create a program and run it,
it begins to execute
in a running process
So, when you run the program,
it's the first function that gets called
That's how you can understand it
That’s why it’s referred to as the entry point
In C#, there is exactly one entry point
So, here, the Main function
serves as the entry point
If we look at the details,
you’ll see the word static,
followed by void Main,
Here you’ll also see the word string,
which means a string, or text
String
And this means it’s an array
And args
represents parameters
If you hover over it, you’ll see it says parameters
We’ll dive deeper into functions later,
when we get a chance,
but for now, let’s test it briefly
As you can see, there is the args variable
We’ll differentiate between when args exists and when it doesn’t
We will output different results based on that
So here, I’ll write
something like this
If there is a value in args,
I will process it accordingly
To check whether there is a value or not,
some consideration is required, right?
That there is a value means this
To check if a value exists in args,
we check if its length is greater than 0
If it is, I will express it this way
If there is a value and the length is greater than 0…
This will indicate that there is a value
If the value exists, we will output
the value from args
Otherwise, we will output
Hello World
So if there is a value,
I want to output the first value in args
Actually, in programming,
we often talk about input and output
Right now, this is written as Write,
Console.Write, which means output
But there is also input
In the console, there is Read
There is Read,
ReadKey, and ReadLine
By using these,
we can read the data
entered from the keyboard
Just remember this for now
For now, we’ll focus on output only
So let’s output it here
If that's not the case,
or if there is no value in args,
we’ll output Hello World
Let’s do this now
This will be covered later,
when we learn about conditionals
But for now, let’s keep it simple
and try it out
If you write if here,
it will automatically
generate the code for you
Let's write it like that
You add a condition here,
and this is for comparison
So these two equal signs mean equal to
It checks if it equals 0
But what I want is, If it’s greater than 0
So you can write this for that
Now let’s proceed with this
If you hold the Alt key and press the arrow keys,
the line with the cursor here
moves like so
You can also group this together
So, press the shift key
and select the block like this,
then press the alt key and move it up and down
It will move together
Using these,
it would be great to code faster
I will press the alt key and move this up
And if not, then this will be
called else
You can write it like this
Let’s try to output this
Here, we will use Console.WriteLine as it is
This is the first value of args
You can write it like this
The first value in an array starts from 0
Since we haven’t
learned things like arrays yet,
you might not understand it well, but let’s try it out
So, this array actually
refers to a list
It means the first item in the list
In computer programming,
we start counting from 0
This is called zero-based indexing
So when it says 0,
it means it starts from 0
Therefore, the length is greater than 0
If there’s one, it would be 1
The first item is 0
You can think of it like that
Let's save this
and try running it
Then, of course, Hello World will be printed
This is because,
when we start this program,
since no parameters were given,
It will show this
Now, to test this,
We should check the generated executable, right?
The current folder is here
When you go to this folder, you’ll see the program
To this open file,
right-click the open file,
and you’ll see an option to Open Parent Folder
Click this to go there
Right behind here,
you can enter the Hello World folder and look
There’s a folder called bin
This stands for binary
Inside the bin folder,
you’ll see a Debug folder
It's Debug because of this
It says Debug here
If you change it to Release and build,
like this, build,
a Release folder will also be created
But I will keep it as Debug
Debug is selected, and the build shortcut is Ctrl+B
So, you can press Ctrl+B
This will build the project
It seems a bit strange
Let’s do it like this
So we will build like this
Let’s delete everything and try again
When you build, the file will be created again
Here it is
Now, let’s look
at the file extension
You’ll see that it creates an exe file
If you double-click it,
Hello World should be printed
But it happens too quickly
for us to see anything
If you right-click here,
I have an option called Open Terminal
Some of you might not see this,
that could be the case
So let me show you how
Here, you’ll see a search button, right?
Type cmd You’ll find something called Command Prompt
This is also called a console
Click it to open the window
You’ll see that black window we saw earlier, right?
Next, we are going to move to this folder
Click here at the top
This will give you the full absolute path of this folder
I’ll copy this
Now, copy it
Then, go back to the console
There’s a command called Change Directory,
which is cd
Change Directory
In programming, we often refer to folders as directories
We’ll move to this directory
So, type Change Directory, then leave a space,
Then paste the part we just copied
Right-click to paste what we have
Now it pastes in
Now press Enter
You’ll see the directory has been changed
We are going to run Hello World.exe from here
Just type Hello World
Instead of typing it all out, type the beginning
Then press the tab key
It will auto-complete
If you press tab several times,
The files with the same name
in the folder will cycle through
Select this one
I will select this
Use it and press Enter
Hello World will be printed
If you want
to rewrite the previous code,
just press the up arrow
It will bring up the last thing you wrote
Then leave a space
Let’s try writing 1, 2, 3, 4
Now press Enter
This time, 1, 2, 3, 4 will be printed
What this means is
when you have an executable file like this,
if you add a space
after the executable file,
it will be stored as a parameter
So the parameter
becomes available now
Then we can
print that value
It’s simple, right?
This is the structure
In this way,
we can create this program
Again, there is the concept of Debug
or Release
Debug is for debugging
It creates an executable file
that helps find bugs
Release is different
it strips everything out for later release or packaging
If you want to distribute it to others,
usually, you set it to Release,
then create it
So, with both Release and Debug,
you can create the same executable file
To recap, this process
is called the build process
Basic Concepts of Programming and the C# Compiler Execution
To clarify the term build,
the build, like this
The build process is this
The source file, the C# code
It's a code
Let's say a code
So this C# code
It turns into an executable file
The process of turning that code into a file
is called build
Then, when this code is
made into an executable file,
The action of making this happen
is called compiling
Yes, this is the structure
I’ll explain this again later
But roughly, this is how it looks
The file that’s created
will be here, as you see
If you look, the Debug file is
about 5KB
Then, as for Release
Ah, it’s the same, 5KB
So, this is how it gets created
Maybe because we haven’t written much,
The size difference is almost nonexistent
But as the code grows longer,
the difference will become noticeable
Also, I unknowingly wrote like this
This is called a slash
On the keyboard, right next to the right shift key,
under the question mark
That’s the one
If you use it twice like this,
this is called a comment in English
A comment
This is called a comment
There are two types of comments
One way is to comment out a single line
So if you look here, if you do this,
everything from here to the end
becomes a comment, that’s the meaning
And there’s another type of comment
It looks like this
Slash and asterisk
Then an asterisk and a slash
That's the other type
This is a block comment
It creates a specific block
for commenting
Like this
Let's try using this
For example,
we can write it like this
Then from here to here, it will be a comment
It’s a bit different
This one comments out the whole line
While this one allows you to specify the start and end
of a block comment
So, in general,
there are two types of comments
If we talk about C language
or C++,
this is the old method
A commenting method used,
in C language
This is the method used in C++,
I can say that
But since this is C#,
instead of distinguishing like that,
We can understand it
as this one comments by creating a block
And this one comments line by line
That's how it works
Now, let’s go back
If you look here, there’s static
Wait, if we look at the structure here,
there’s also Internal
These all have meanings
I’ll explain these later
when I talk about classes
For now, I’ll talk a bit about this
To explain this briefly,
What we’re seeing here
are what we call variables
In this lecture,
we’ll talk about variables next time
But to put it simply,
a variable is a container
That holds a value
that container is stored somewhere
So this container
is saved somewhere
So, we need to understand
this concept in terms of computer structure
So, we’ll talk more about builds later
Let’s take a look at computer structure
This is how a computer looks
If you open up a computer, you’ll see the motherboard
And somewhere here
is the central processing unit, the CPU
Then memory goes here
This is memory
What we usually call RAM
It’s called Random Access Memory,
like Samsung RAM, Hynix RAM,
and so many more
RAM goes here
And also, SSDs
Things like that go in here
The RAM is long and shaped like this
So these are SSDs
In the past, we used to call them HDD
Hard Disk Drives
That’s what we called them
If you look at it broadly,
this is called the Central Processing Unit
The Central Processing Unit, CPU
Then here’s the memory
This is the main memory
This is called secondary memory
Actually, computers
can be seen as having benchmarked
human brains and concepts
When a person has a brain
The brain is here, right?
What the brain mainly does
is two things
To handle calculations,
and handle memory, right?
So in a computer,
there’s the CPU that handles calculations
and the memory that handles storage
Secondary memory like this
isn’t really like the human body
It’s more like a diary or your phone
where you store things
That way, the memory
can be retrieved again
So you can think of it that way
When we need to handle information,
we need to store it, right?
So here, the parameter
is like a container for storing
Something in memory
This memory is usually thought of
So that container is ultimately
stored in memory
So that memory is usually thought of
as main memory
or secondary memory
To be more precise,
the part of memory
that we use
is the main memory
The secondary memory
is where our files
are actually stored
Of course, strictly speaking,
there’s something called paging techniques
where part of the secondary memory
is used by the main memory
But even without considering that,
You can divide it like this
So that’s the explanation
So that's what it is
This is how it looks like
So, in the end, we’re storing values
in memory
This is what we wrote earlier
when you write it like this,
It gets stored somewhere
and then it comes over here, right?
It’s passed over, and that’s the concept
that we use
So that container is ultimately
stored in memory
Is memory a single space?
No, it’s not
Memory is divided into parts
To put it simply,
it’s divided into four main sections
So it’s split into four areas
There’s the code area
Then the data area
Next is the heap and the stack
These are the areas
But code is usually
what we’ve written in our program
That’s what’s stored as assembly language
The actual code becomes machine language
You can call it machine language
Those machine instructions
are stored in memory
That’s the code area
Then the data area contains static variables
In C#, it’s where static variables
and global variables exist
That's what it is
The heap is the space we create when needed
and remove when it’s no longer necessary
It’s where memory is dynamically allocated
So usually when you create memory
with the New keyword
That memory
is called the heap
The stack is for function parameters
or local variables
Since this is your first time, it’s fine if you don’t understand everything
But it’s good to have an idea
that memory is divided this way
That's what it is
The key feature of these
is a concept called the Lifecycle
It's called Lifecycle
Simply put, the application app runs,
and then it ends, right?
During this time,
the variables use memory
when they’re created,
and when they disappear
That's the gist of the lifecycle
So, the code will naturally
continue to exist
until the application terminates
The same applies to the data section
Both of these exist while the app is running
and disappear when it terminates
The heap, however, can be created and destroyed by the user
The stack is allocated when a function is called
This process is known as a function call,
when the function call is made, memory is allocated,
and when the function terminates, the memory is freed
For now, you don’t need to fully understand these concepts,
but the key point I want to emphasize here
is the term static,
spelled as static
It is something
that exists from the very beginning
It is created at the start
and remains throughout execution
In other words, static elements always exist
Since they disappear only when the app terminates,
they effectively persist
for the entire runtime of the application
That’s why the static keyword
is used here
So see here
We have static and Main functions
This Main function exists
from the very beginning,
right from the start
That’s why the static keyword is used here
All static elements
are created at the same time,
so they exist together throughout execution
Like this
Now, let’s wrap up
the explanation of Main
The Main function
is referred to as such
It's an C# application
Application,
or app for short
It is the entry point of a C# application
That means it is the very first function
when what starts?
When the app starts
It gets called
when the application starts
That's what it is
This is why Main is known as the entry point
In C#, there is only one entry point,
which means
a program can have
only one Main function
So there's only one Main function
That's what it is
If we visualize this with a diagram,
it would look something like this
There is an operating system,
commonly abbreviated as OS
Operating system
Some examples of OS
include things like
Windows,
which we use a lot,
Mac or Macintosh,
Macintosh
Linux, and Unix
For mobile devices, we have
operating systems like Android
The operating system
runs applications,
which execute within its environment
So, in the OS,
an application runs as a process
When it starts, the very first function that gets called
is the Main function
That's the structure
Applications, in another term,
are also called processes
To explain this further,
it can be a little tricky
If you right-click on your desktop
and open the Task Manager,
here,
you will see a section
labeled Processes
All the running applications are listed here,
including both active applications
and background processes
This means an application
is just one type of process
Hopefully, this gives you a general understanding
This isn’t a difficult concept
Once you grasp the structure,
everything becomes clearer
So that's what it is
Let's summarize this
And there’s one more thing I want to mention
The question here is,
how does C# actually run?
Earlier, I talked
about the build process,
When we talk about builds,
it applies not only to C#
but also to languages like Python,
Java, and more,
like C, and C++
Same thing here
In the build process,
we write code using a structured,
human-readable programming language
For example, in C#, it's a C# code
So this is essentially a file
we write code in .cs files
That's the extension
This code then
needs to be compiled
When we compile it,
it first gets translated
The build process may differ
with different languages
Let me start with this first
For C#,
it gets translated into an intermediate language
this intermediate language is packaged
into either an exe or dll
like .exe
Exe refers
to executable file
Dll means
dynamic link library
So it's a dynamic link library
That's the file extension we get
Metadata is also generated alongside these files,
so we have these here
So we have these files
Now, to actually execute these files,
the operating system needs to interpret and run them
Now, when the necessary information
moves through this process,
something happens here
There’s something called the Common Language Runtime
or CLR
It's called Common Language Runtime
During compilation, the intermediate language
is usually called CIL,
or Common Intermediate Language
That's CIL
So, CIL is generated as an intermediate language
In Java, this would be referred to as bytecode
It's called a bytecode
But calling it an intermediate language
is more accurate in this case
Anyway, this intermediate language
is created like so,
and then something called CLR processes it
CLR converts it into native code
That’s what happens
In Java, this process is handled
by something called VM or Virtual Machine
C# has a very similar structure to Java
This is why we call it the .NET environment
It’s commonly known as the .NET Framework
A .Net environment
When we build C# code,
it produces an intermediate language file
This file is then
processed inside the operating system
by a virtual machine, or the CLR,
which converts it into native code
That native code is what the operating system
actually executes
That’s the structure of the process
So, all we need to do is write the code
Then, with this,
when we compile it,
an intermediate language file like .exe or .dll is created
With that file, the program can be run
on various operating systems
So that's the Virtual Machine
That’s why it’s all
called a virtual machine
Through this virtual machine,
different operating systems
are able to run the program
The system is pre-configured
so that it can execute properly regardless of the OS
That’s how execution works
This is the build process of C#
From building to execution,
this is the full process
In C, the process is different
It's not like this
C first goes through preprocessing,
then compilation
After that, it generates object files
Then, the linker takes these object files and links them together,
combining them into a final .exe file
That's how it works
For this, the compiled and linked executable is different
Each OS generates a different type of executable
so C programs aren’t inherently cross-compatible
C# was designed to be more universal,
unlike other languages
So it first compiles into an intermediate language
Then, this intermediate code is processed
by a Common Language Runtime or CLR,
which acts as a virtual machine to convert it
into native code for the specific OS
That's how it works
Let's summarize what we've learned today
Summary Installing Visual Studio & Running Hello World Install Visual Studio through Visual Studio Installer
The installer expands Visual Studio’s functionality Create a new project → Select C# under All Languages (L) Select Console under All Project T
Enter Project Name and Solution Name, then click Create WriteLine Hello World
Debug: Creates an executable for debugging Release: Creates an executable for distribution
Programming Basics and C# Compiler Execution Process Build: The process where C# code becomes an executable Main Function: The first function call
Compilation: The step before code turns into an executable Variables: Store values in memory Memory Sections Code: Machine code stored in memory
Data: Stores static variables Heap: Allocates and deallocates memory as needed Stack: Stores function parameters and local variables
C# Compiler Execution Process Write C# Code Compile C# files, generating .exe or .dll intermediate language
CLR (Common Language Runtime) in .NET converts this into native code Native code runs on the OS