C# Programming for Beginners - C Sharp Coding Basics | Mika Jäntti | Skillshare

Playback Speed


1.0x


  • 0.5x
  • 0.75x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 1.75x
  • 2x

C# Programming for Beginners - C Sharp Coding Basics

teacher avatar Mika Jäntti, Game Development | Coding | 3D Graphics

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Lessons in This Class

    • 1.

      Learn to Code!

      0:41

    • 2.

      What are Variables?

      3:55

    • 3.

      Using Variables in Code

      5:03

    • 4.

      What are Condition Statements?

      4:22

    • 5.

      Using Condition Statements in Code

      2:53

    • 6.

      What are Functions?

      4:26

    • 7.

      Using Functions in Code

      3:17

    • 8.

      What Next?

      0:46

  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.

104

Students

--

Project

About This Class

Learn to code with the C# programming language! In this course, you'll get to know three basic programming concepts, which are variables, condition statements, and functions. These concepts cover a large part of the entirety of programming and can be used as such in real-life programming projects. They are also pretty similar in other programming languages like Python, JavaScript, and Java, so even if you aren't interested in C#, this course can still be useful for you.

In this course you'll learn:

  • how to store and use values in code using variables
  • how to check for conditions and execute only certain code using condition statements
  • how to create your own functions and pass parameters

Enroll in the course, sit back, and enjoy while learning one of the most useful skills in this modern world!

Meet Your Teacher

Teacher Profile Image

Mika Jäntti

Game Development | Coding | 3D Graphics

Teacher

I teach skills such as Game Development, Coding, and 3D Graphics. My goal is to create high-quality content where I always get straight to the point. In addition to online courses, I develop and publish video games on Steam and provide 3D visualization services for companies. Make sure to follow me here so you'll know when I publish a new course. Thanks!

See full profile

Level: Beginner

Class Ratings

Expectations Met?
    Exceeded!
  • 0%
  • Yes
  • 0%
  • Somewhat
  • 0%
  • Not really
  • 0%

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.

Transcripts

1. Learn to Code!: In this course, you'll learn about coding with the C# programming language. You'll get to know three basic programming concepts, which are variables, condition statements, and functions. These concepts cover a large part of the entirety of programming and can be used as such in real life programming projects. They are also pretty similar in other programming languages, so even if you aren't interested in C#, this course can still be useful for you. Enroll in the course and to learn one of the most useful skills in this modern world! 2. What are Variables?: Let's get to know the first concept of the course, which is variables. What are variables and what is their purpose in code? A variable is used in the code as a so-called memory location where the developer can store a value. The structure of a variable is as follows. It has a type that determines what kind of value it holds. There are several different variable types, each with its own purpose. A variable must also have a name that can be referenced in the code in order to use the variable, the developer can decide the name of the variable themself. A value can be stored in the variable either when it's declared or at a later stage. If a value is not set for the variable when it's declared, it uses the default value of each type. Let's use an example to get to know the four most common variable types in CSRP. Imagine you have a program that handles data about different kinds of cars. Information about a car can be stored in different types of variables. One of the most essential detail about a car is its brand. Because the brand of a car is indicated as text string variable type would be used for these kind of data. The name of the variable should be something that describes the stored information. Well, in this case, the variable could be named brand. For example. The value of the variable could be Toyota. Note that the value of the string variable type must be enclosed in quotation marks. The default value of the string variable type is null, which means that the value doesn't exist. The next essential piece of information about our car is the year in which it was produced. Years are specified as whole numbers. So it makes sense to use the variable type to store these data. The variable could be named year, and given the value 2012, the default value of the variable type is 0. Another common detail about a car is its engine capacity. This fact is displayed in leaders to one decimal place. For this type of information, you could use the double variable type because it takes a value that contains decimals. An adequate name for this variable would be Engine capacity. If a variable has multiple words in it, they should be written together. It's good practice to write the first word in lowercase and the rest of the words with a capital first letter. The value of this variable could be 1.3. Remember to use a decimal point, not a comma. The default value for the double variable type is 0. The next significant detail about a car is whether it has an automatic transmission or a manual one. This piece of information should be stored as a bool variable type because that type has only two possible values, either true or false. A suitable name for this variable would be, is automatic. Since this particularly Toyota has an automatic transmission, these automatic variable would be given the value true. The default value of the Boolean variable type is false. 3. Using Variables in Code: Let's now take a look at how variables can be utilized in code. The first step is to declare the variable. Declared a variable that contains an integer value. So use the int variable type. Next, the variable must be named, name it x. For example, this variable will not be given a value added stick layering stage. So end the line by adding a semicolon after its name. The semi-colons in the code delta programme when each line ends. However, there are some exceptions. When a line doesn't end with a semicolon, you'll learn about them in the following lectures. There is now an integer variable in their code with the name x because you didn't give a value to the variable. We need vast declared. It uses the default value of its type, which is 0. Let's declare another integer variable that will be given a value when it's declared on a new line, write the type of the variable that is int. Name it. Why? For example, in order to set a value for a variable, an equal sign must be added after its name. The equal sign type, the value that you want to assign to the variable success three. And the line by adding a semicolon at the end of it. At this stage, the value to the right of the equal sign is assigned to the variable on the left of it. Now that you know how to declare a variable, Let's see how it can be used in the code on a new line. Call for an existing function that can be used to print messages to the console. Inside the console class is a function called write line that does just that. The value you want to print to the console should be entered inside the parentheses of the function. Type the variable name y inside them. Now when the code is executed, the print function prints the value of the y-variable to the console, which is three. The value of a variable can be changed after it has been declared. Before printing anything, add a line where the value of the y-variable is changed to 5. First, type the name of the variable. That is, why after that, add an equal sign, then a value you want to replace the old value with. Lastly, end the line by adding a semicolon at the end of it. Note that this time the word int wasn't added in front of the variable name because the y-variable has already been declared in the code, this line only changes its value. When the y variable is declared, it's given a value of three, but right after that, it's replaced by five. Finally, the value of the variable, which is five, is printed to the console. As you can see, the order of the lines in the code matters. This code is read from top to bottom line by line. Let's now assign a value to the X variable after it's been declared. The line begins with the name of the variable, followed by the equal sign. And the value you want to set for the variable, give it a value of two and end the line with a semicolon. Modify the call for the print function so that it doesn't print the value of the y variable, but the variable x value. When the code is executed, the value of the x variable is printed to the console, which is two. You can utilize mathematics in the code such as plus minus, multiplication and division calculations. Modify the call for the printf function so that it prints the sum of the x and y values. Add a blast sign after the x-variable, then the y variable name. Before the write line function brings anything to the console. The equation inside each parenthesis is solved, which is x plus y, that is two plus five. The sum of these two values is printed to the console, which is seven. You can change the plus sign, the minus to perform subtraction calculations. To perform MALDI populations change design to an asterisk. The perform division calculations, Jane's design to be a forward slash. 4. What are Condition Statements?: Let's move on to the second concept of the course, which is condition statements. One, our condition statements and what is their purpose encode. Condition statements can be used in code to check whether a certain condition is met or not. Or of the condition statements is the if statement. Its structure is as follows. It starts with the keyword if, which is followed by parentheses. After them, curly brackets must be added. The structure of the if statement is now complete. As you can see, condition statements don't end with a semicolon. The condition that should be checked is added inside the parentheses of the if statement. If the condition is met, that block of code inside the curly brackets of the statement will be executed. If the condition is not met, the code inside the curly brackets will be skipped. If there is a call for the print function inside the curly brackets of the if statement and the condition is met, the message will be printed to the console. If the condition is not met, no message will be printed. In many cases, you want to execute a certain code when the condition of the if statement is not met. To do this, you would use the else statement. The structure of the else statement consists of the keyword else and girl in brackets. So if both statements have the call for the printf function inside them, and the condition of the if statement is met. The block of code inside the if statement will be executed and the else statement will be skipped altogether. In cases where the condition of the if statement is not met, the block of code inside the else statement will always be executed. So in an example like this, the program will always execute either the if or the else statement. When you want to check for multiple conditions, you can use the else if statement. The statement must always be below the if statement, but above the L statement. The structure of the else if statement is as follows. It starts with the keywords else if weeds are followed by parentheses, curly brackets, there condition that should be checked is added inside the parentheses. There can be several consecutive elseif statements. The program will first check the condition of the if statement. If that condition is met, all the elseif statements will be escaped even though they are conditions would have been met. The else statement will also be skipped. If the condition of the if statement is not met, the program will check the conditions of the else if statements one-by-one, if one of them is met, the block of code inside that particular elseif statement will be executed and the rest of the statements will be skipped, even though they are conditions would have been met. In cases where the conditions of the if statement and the else if statements are not met, the program will execute the code inside the else statement. When using condition statements in code, user to remember the following rules. The if statement is the only required statement. There can only be one of them, and it must be the first statement. The statement is optional. There can only be one of them, and it must be the last statement. The if statement is also optional. There can be multiple elseif statements and they must be below the if statement, but above the else statement. 5. Using Condition Statements in Code: Let's now take a look at how condition statements can be utilized in code. Let's write a simple program that prints the day of the week to the console, depending on a certain number. Start by declaring an int variable named day of the week, give it a value of one and end the line with a semicolon. Next, add an if statement by typing the keyword if, followed by parentheses and curly brackets. In the condition of the if statement, Let's check whether the value of the day of the week variable is one. This can be done by typing the name of the variable followed by two equals signs and the number one. The first day of the week is Monday. So inside the curly brackets of the if statement at a call for the print function with the message today is Monday. When the code is executed, a message is printed to the console that says Today is Monday because the condition of the if statement was met. Keep in mind that there's a big difference between 12 equal signs with one equals sign of value can be assigned to a variable. The two equals signs is one of the comparison operators that can be used to check whether the value on the left side of it corresponds to the value to the right of it. If the value of the day of the week variable is changed due to the condition of the if statement is not met because the value of the variable is no longer a one. There are seven days in a week, so let's add a statement for each of them. You have already covered Monday in the if statement. So add six else. If statements for the rest of the day is the number in the condition and the content of the message of faith. That particular day of the week, where you change the value of the day of the week variable to six. For example, a message that says The day is Saturday should be printed to the console. You may also want to add the else statement to handle all the other scenarios where the value of the day of the week variable is something other than between 17. Add the call for the print function inside the curly brackets of the L statement with a message that says error. If the value of the day of the week variable is changed to 587, for example, the block of code inside the else statement will be executed. 6. What are Functions?: Let's get to know the third concept of the course, which is functions. What are functions and what is their purpose in code? Functions can be called in the code to perform a certain task. A good example of this is the existing right line function that prints a message to the console. In addition to existing functions, the developer can create their own functions and call them at different stages in the code. By using functions, that code can be split into smaller parts, making it easier to read and work with. So far, you have only worked within the main function which is executed when the program is started. The main function is currently the only function inside the program class. Declare a new function called either by typing static, void hi there, followed by parentheses and curly brackets. In C-Sharp, the first letter of each word of a function name is capitalized. When you compare the main and hide their functions, you'll see that the main function has a value inside its parentheses, but the hide their function doesn't. Values inside the parentheses of a function are called parameters. When you call for a function, you can pass values to it as parameters. A good example of this is the write line function. Every time you have called for it, you have passed a string value to it as a parameter. The write line function has then used the value as the content of the message that has been printed to the console. Both the main and high their functions have the keyword void before their names. This is the type of the function. Void means that the function doesn't return a value. Both functions also have the static keyword in them. When a function is static, it can be called directly. A good example of this is again, the write line function found inside the console class. Currently, there is no code inside the hide their function. So let's add a Call for the brain function inside it with a message. Hi there function says high. When the code is executed, only one message is printed to the console that comes from the main function. This is because the program never reads the code inside the hide their function. It only reads the code inside the main function because it's the default function that is executed when the program starts. In order for the program to read the code inside the height their function, it needs to be called in the main function, type Hi there, followed by parentheses, end the line with a semicolon. Now when the code is executed, two messages are printed to the console. The program starts reading the code from the main function, where the write line function is called. The printer main function says Hi message to the console. After that, the high their function is called. The program starts reading the code inside it. That's when the write line function is called the printer. Either function says Hi, message to the console. When the program has read the code inside, the higher their function, it returns to the main function and continuous reading it. As said before, the write line function is found inside the console class. This class and all of its functions are written by some Microsoft employees that are, so to speak, letting you use the functions in order to make your work easier. The high, their function is found inside the program class, which is free then by you. When I'm calling the hide their function, you don't have to type anything in front of it because the function is found inside this glass. If you wanted to call the height their function in one of your other classes, you would have to type program hi there In order to call it. 7. Using Functions in Code: Let's now take a look at how functions can be utilized in code. Let's write a simple calculator. Start by creating a function that will be used to perform calculations. Declare a function called Plus by dy being static, void plus followed by parentheses and curly brackets. Let's make the function so that two whole numbers can be passed to it as parameters when it's called in the main function. The function then prints the sum of the two numbers to the console. Inside the parentheses of the function, declare two int type variables by typing int x comma int y. Now type the goal for the print function. And inside each parentheses type X plus Y. They won't be given values at their declaring states because they will get their values when this function is called. Next, called the plus function in the main function by typing plus followed by parentheses and a semicolon. There. Blast function requires two int values as its parameters inside the parentheses type. For example, 24 comma 32. When the code is executed, the two values inside the call for the plus function, which are 2432, are passed to the function where their sum is printed to the console, which is 56. Let's now create a function that can be used to perform subtraction calculations. Declare a new function by typing static, void minus, followed by parentheses and curly brackets. Inside the parentheses declare two int type variables by typing int x comma int y, and call for the printf function where you subtract the two values. Keep in mind that the x and y variables of the minus function have nothing to do with the x and y variables of the function. Parameters are function specific. Lastly, call the minus function inside the main function, pass the values 7225 as the parameters. For example, when the code is executed through messages are printed to the console. The first message is 56, the sum of the values 2432. The second one is 47, the subtraction of values 7225. You can also declare functions for multiplication and division calculations. The only difference is the name of the function design between the x and y variables and the values that are passed as parameters. 8. What Next?: Congratulations on completing the course. I hope you learned a lot. I have created a discussion where you can submit your ideas on what courses I should make next. Should I dig deeper into the three concepts taught in this course, or should I D, it's other parts of C Sharp, such as operators, loops, and classes. If you think printing messages to the console is a boring way to learn programming, I can create a course where you get to code your own game using G-sharp. Let me know by replying to the discussion. Also, makes sure to follow me here on Skillshare. So you'll know when I publish a new course. Thanks.