C# Programming: Basic Code for Beginner Programmers | Matthew Dewey | Skillshare

C# Programming: Basic Code for Beginner Programmers

Matthew Dewey, Writer, Writing Tutor

C# Programming: Basic Code for Beginner Programmers

Matthew Dewey, Writer, Writing Tutor

Play Speed
  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x
12 Lessons (1h 14m)
    • 1. Introduction to Beginner C#

    • 2. Visual Studio Download and Installation

    • 3. First Line of C# Code

    • 4. Data Types and Variables

    • 5. Number Data and Operators

    • 6. Boolean and Data Type Conversion

    • 7. If Statements

    • 8. Nested If and Additional Operators

    • 9. Retrieving User Input

    • 10. The While and For Loop

    • 11. Final C# Project

    • 12. Conclusion to Beginner C#

  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels
  • Beg/Int level
  • Int/Adv level

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.





About This Class

Welcome to Your Beginner C# Course!

C#, one of the most popular programming languages in the world and for good reason. It is generally used to create useful software, video games and apps. However, like with learning any language, studying C# can be a difficult process, but it doesn’t have to be.


My name is Matthew Dewey. I have been teaching programming for over 4 years and have written books on the subject of programming, from learning the languages themselves to how to make a career from programming.

My approach to teaching is purely practical. The best way to teach programming is not through the memorising of code, but the application of that code. I will show you the code you can write out and test for yourself.

You will learn how to:

  • Install your software, Visual Studio

  • Establish fundamental code

  • Create and use variables

  • Retrieve user input

  • Process simple data

  • Create simple programs

  • as well as BONUS tips and code!

Go no further if you're looking for the course that will guide you into the world of programming! With my course, I can guarantee that the knowledge you learn will help you get a head-start in C# programming.

I hope you enjoy the course and it helps you on your way into the world of programming!

Meet Your Teacher

Teacher Profile Image

Matthew Dewey

Writer, Writing Tutor


I have been writing and teaching for years, helping tens-of-thousands of students achieve their goals, be it completing their novel or publishing their work. Having written several novels, non-fiction books, hundreds of short stories and articles, I have studied and put into practice the best methods for writing effectively and efficiently.

In addition to writing, I am also a programmer and artist, teaching what I know on the subject and helping those interested get a headstart.

If you want to write a novel, a story that has been on your mind and not on paper for too long, my courses will not only help you start, but I will be there as well. Any work you submit, I will happily read, review. If you need professional advice or a friendly opinion, I will be there for both.See full profile

Class Ratings

Expectations Met?
  • Exceeded!
  • Yes
  • Somewhat
  • Not really
Reviews Archive

In October 2018, we updated our review system to improve the way we collect feedback. Below are the reviews written before that update.

Your creative journey starts here.

  • Unlimited access to every class
  • Supportive online creative community
  • Learn offline with Skillshare’s app

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.



1. Introduction to Beginner C#: C-sharp is one of the world's most popular programming languages, being used to create software, videogames and help construct brilliant apps. C-sharp has a variety of many uses. It is no wonder that so many students today are studying this incredible language. But that said, C-sharp presents many challenges for the beginner programmers. It isn't an easy language to learn in the beginning, but that's where this course will come in handy. My name is Matthew doing. I've been teaching programming for over four years, and I've written books on the subject of programming from learning the language themselves, jar to make a Korea from programming, my approach to teaching is purely practical. The best way to teach programming is not through the memorizing of code, but the application of that code. I'll show you the code. You can write it and test it out for yourself. For this course, I'll be using Visual Studio. And it is the IDE that I recommend all beginners used when learning C Sharp. Now this is a course for beginners, so you don't need to have any experience of C-sharp or programming to learn in his goals. And this course, I'll teach you your first line of code. Show you what variables and data types and I'll show you how to retrieve user input, take that data, process it, and turn it into information with if statements and loops. Throughout this course, I'll be providing you with practical work and exercises so that way you can cover everything as much as you need to perform movie none and two capitals. There'll be a final project to test all that you have learned in this course. All this and more will be kept in a workbook on C-sharp, which I will be providing you in this course as well. So that way you can practice your c-sharp programming offline if you need to, or use the workbook as a handy reference when programming. If you're looking for a hands-on course to teach you c-sharp programming. This is the one for you. I look forward to seeing you in the first lesson. Bye for now. 2. Visual Studio Download and Installation: Hello and welcome to the first video in your c-sharp programming course. And this video we'll be downloading and installing Visual Studio. This IDE that we'll be using throughout this course. To begin, we first need to download it from a browser of choice. Are we using Google Chrome? Simply go to your search bar and type in Visual Studio. The first result should be the correct one. So simply clicking on the Donald's option here, or through the main website and going to downloads. Once on the downloads page, you should see the following. Here you can download a version of Visual Studio that you want to use. How are we using the community edition as it is free. So any student willing to learn C Sharp has access to it. If you're not using Microsoft, you can find the downloads for the other versions below here. But I am using Microsoft SAR starts the Downer by simply clicking here. It will take you to a thank you page. And you should see the download begin in the bottom left corner. You can run the installation by clicking on this icon down here, or by simply clicking on the installation file in your downloads folder. Or as I have it here on my desktop running that installation at will ask you for administrative privileges. Simply click yes. You should see the following inbox, Pia, click, Continue to start the installation. From there, you should see the following. This allows you to choose which additional workspaces you want to install it with the Visual Studio Code editor. Now, there are many options to choose from, but there's only one that we'll be using. And that's the.net desktop development. This would give us all that we need to work with C sharp. Of course, if you're more experienced with C-Sharp, you can go through the other workspaces and select which ones are useful to you. But be sure to select the.net desktop development. So we can have all that we need to do some c-sharp programming. Once you have done that, simply click Install And to now begin downloading all the necessary files and installing them as they go. Now this can take awhile as it is a sizable file. So I'll see you in is complete. And once the installation is complete, you're ready to go. You can simply click the launch but any air or go to your start menu and search for Visual Studio 2019. As this is the latest version that I am using. One stun, you replace the acronym desktop if you wish, and simply start the program. Now, Visual Studio may ask for you to sign, in, which case you will have to create an account if you haven't already. Once that's complete, present you with this box here. This is the box that you first see when creating a Visual Studio project. To do so you simply click down here, or you can open any other projects from up here. And that concludes this installation. And the next lesson, I'll be showing you how to create a project in Visual Studio. And your first alarm of C-Sharp code. I will see you then. Bye for now. 3. First Line of C# Code: Hello and welcome back to your c-sharp programming goes. In this lesson, we'll be creating a project in Visual Studio and rots enough first-line of C-Sharp code. Now, first things we need to do is create a new project by simply clicking here. This will take us to a window where we can sit which framework we want to use, as well as which language. Now this is a beginner course, so we don't need to use anything major that you might be seen here. What we're gonna do in this video is create what is known as a Console Application and Visual Studio, which allows us to enter in some basic code and receive a basic output for that code through a console window. Now, to find this framework easily, you can search a chair at the top, or simply put in c sharp in the languages and got a project up and select the console. You will see dominate coal and.net framework. Once you've done that, simply click next. Here, we're going to now give a name to our project. I'm going to call it something basic. First, program, X0 and click Create. Once that is done, you should see the following. Now this may seem a bit overwhelming at first, but we'll be going through what all this means in a moment. First, I am going to be customizing Visual Studios for making it easier for us to look at. Right now the blank white screen can be a pretty harsh and ours. So to customers that are going to Tools, Options. I click on environment here and I change the color theme from blue to dark, like so. As you can see, this changes everything to a dark background to make it a bit more easy to look at as well as for you to watch. In addition to that, I'm going to make the code a bit easier to read as well by zooming in, by simply holding down Control and scrolling up on the mouse wheel until it's big enough to see. Was that done? Let's go through what's on the screen now. And let's begin a cause there's only two things that really concern us. First, and most obvious is the Code window that you see here is this code window that we can place our occurred. As you can see, some default code is really put in and I'll go through it as well. The second thing is projects manager over here and the Solution Explorer. This organizes our projects as well as every bit of file attached to it. So as you can see, our program is attached to it as well as its various properties and references already set for us through the Visual Studio defaults. Now, we now need to go into depth with this. This is a beginner goals, but we really need to do right now is len off islam occurred. But before we can do that, we've got to understand where we need to write our code. First of all. So let us go back to our Curtin window here and go through what you see here. First, you'll notice a block of code at the top here. Below this block of code, we have these three lines and sits on brackets. Now, think of an application as a collection of classes. These classes work together to create a working program with their array of methods at their disposal. So namespace first program is our project's main program. Within it is a class or many classes, in this case just one code program. And within this program is a method, the main method, which is the method that is executed upon or running a class. And you can see here. And it is within this set of code brackets below the main method that will be writing our code. So that way when we run our application, what it does is it calls our namespace per gram and then calls its class. And that class in turn cause its main method and runs the code within. The class can contain several methods much lack a method can contain several lines of code. And if we go broader than that, and namespace fears program over here can contain many classes, all of which can work hand in hand. I can go more in depth with what this is and what it means as a programmer. But that is something that is most suitable for an advanced course. For now we are beginners and we simply want to rush off first line of code and will be placing it right here between these two code brackets in the main method. Now the first line of code that any programmer lens is an output line of code is simple line of code that's simply outputs a line of text. Now there are many different languages out there that have their own unique code for outputting a line of text. So let's deal with, Let's learn C-sharp S1. Simply tapped in console capital C. Take note of the case when writing code, as it is important. Now, what this does is simply call the console class. And what we then do next is put a dot and we tap and a method that works with that console cause one we're going to be cooling is right line like so. Notice capital W, capital L, a set of normal brackets, otherwise known as parentheses, and a semicolon to close off that line of code, most lines of code you will find end with a semicolon. Now what this does is output nothing at the moment. What we need to do is add text between the parenthesis over here. By simply adding a double quotation mark. A line of text such as hello. World. Now introvert an app first line of code we need to build and run our program. In order to do that, we make use of a shortcut by simply holding down control and pressing F5. So it is built and run the program, as you can see here, and opens up the console window. And in that console window, we have our first line of text. And it simply says hello world. And press any key to continue. If you press any key, it will close the program and it will end. A very simple line of code that you'll find it is one of the most useful lands of code. As output is what we want to receive from any software that we use. We give our input and in turn, the program performs some sort of service and shows us an output. And there you have it. But this first line of code, you're now ready to learn more lines of code that can work together to create pool functioning programs. However, before we do that, we need to learn about data types and variables. And we'll be learning about that in the next lesson. See you then, bye for now. 4. Data Types and Variables: Hello, and welcome back to a c-sharp programming course. In this lesson, we're going to be introducing you to variables and two data types, string and char. But you'll find out what those are in a moment. Now before I introduce you to variables, I must tell you about data types. It suggests they are different types of data in programming, there are a number data tabs and our text data types. What we're learning in this video is text data types to dollar tubs in particular. One is the string data type, which contains lengthy valleys of text. For example, sentences, paragraphs, even an entire book can be made into a string value. And a second char, which is a shortening of character, can contain only one character of the text data. This can be anything from a hashtag to a number, to a later even whitespace, as long as it's a single character. Now let's talk about variables. Variables can come in different data types. And when we create a variable, we say what kind of data tab is assigned to that variable. So other data types cannot be assigned to it as well. Of course, that's all just theory, so it's better to explain it with some practice. So let's create a variable now. We will start with a string variable, simply tapped in string, and give you a variable, a name such as name and a school STR. The reason I get the variable this name is because it helps me understand what the string variable is about. For example, it is a variable that will contain a name. And the underscore STR tells me that is a string. So that way, if I encountered later in a lengthy program, I can understand what the variable is used for and what data tab is the sun to it. And I close with a semicolon. It's as simple as that to create a variable and assign it a Data tab. But now we need to give it a value. To give it a valley, we simply tap in link, underscore STR again equals. And for a string variable, we need to give a string data. And the way we do that is double quotation marks. And within those double quotation marks, we write our string. And as I said before, you can put an entire book into a string variable. Simply paste that book between these two double quotation marks. But for now, let's just give it a simple, a lot of text seen as it is called name. I'm going to give a name such as John Smith. And once more in this line of code with a semicolon. And now I can call upon this variable anytime I want to. So let's say I create an applet land, like so. And I put name underscore STR between the parentheses. And now let's run the program control if bath, and as you can see, it prints John Smith and that's simple to create and use variables. But now let's simplify this creation of a variable by taking the value that we're assigning it and placing it within the same line as our creation. So I'll copy this and I'll paste it here. And then I can take out this LAN as I've included it here. So we've just optimized our code somewhat and it does the same thing. So that is one data type and its variable. Let's say that we want to make this variable constant so that way it cannot be changed later in the program. As this is mistake that is often made by programmers when they creating large applications and it's easier to do. Simply just put name underscore HDR again. And we can give it a new line of text and just say hello, yeah, and close with a semicolon. What we are doing here is overwriting the value for this variable. When we run the code, it prints hello nouns did have John Smith. But we want this value to remain constant so it doesn't get changed by accident. The way we can do this as simply adding CON AST before the string. Con is T is constant, making the variable that follows constant, ensuring the value cannot be changed later in the program. As you can see here. And the land below name underscore string is underlined in red. This is because it is creating an error in the code. If we were to run our program, you'll notice that this is, there's errors right now. And as you can see, an error log below, it tells us exactly what is happening. Let's take out this line of code to make sure our program works. Now that is one data tab let's talk about the other, takes datatype char. Now to create a char variable, it's as simple as a string variable. C-h-a-r. Give it a name just like before. I'm just going to call those character and the school CH equals. And now for a char variable, we must use single quotation marks instead of double quotation marks. So I'll just put a dollar sign here and follow two for semi-colon. And I can add, put this variable the same way as you can see here. And just like with a string variable, as with any variable, we can make it constant by adding CON ISTE beforehand. So that way we can't change the variable's value later in the program. Now said, said, these variables can work with each other. For example, let me adjust the string variable. Yeah, I'm just gonna call it word underscore string. And I'm going to put programming between the double quotation marks and hashtag between the single quotation marks with a character variable. And I can put these together by simply making use of some operators. Operators being plus or minus equals we've already used. We can add a string to this output. Just like that. I run the program, it prints hashtag programming. It's that simple to combine different values that we have collected in our program with other data. For example, I can add text in this output line as well. So I'll put double quotation marks. I am space after the double quotation marks. And now when I run the program, it says I am hashtag programming. And then you have basic variables and text data taps. In the next lesson we'll be going over number, data tabs and math functions. But before then, I do recommend that you complete the exercise in your workbook. As you'll learn a bit more code to work with these data types and variables. But that said, I'll see you in the next video. Bye for now. 5. Number Data and Operators: Hello and welcome back to your c-sharp programming course. In this lesson, we're gonna be learning some number data taps and math functions. Now there are several number data tabs that we can work with. And I'll be going over quite a few in this lesson. Although throughout this course we will mainly be falling back on two different data types. And I will be going over those in a moment. First, let's talk about some whole number datatypes. They are full in particular that we can work with. The first hall number data tab is the byte data tab, which has a range of 0 to 255, inclusive of those numbers. Next, we have the short Data tab, which has over negative 32 thousand to 32 thousand as its range. And the most common one will be working with is short for integer, which has a range of negative 2.1 billion to positive 2.1. Now this is a ridiculous range to work with, and this is why it is the most common one to work with. As you may be, encountering numbers far larger than the number of values that short can provide. That int will provide those values for us. And if we wanna go even further than that, we can use Long. Now, as long as the numbers that you're working with, FET the ranges of these data types, you can create a variable using any of them. Annual program will work as long as those ranges are not exceeded. And these are only the whole number data types that we're gonna be working with. We also have decimal tabs. For example, 5.6 or negative 12.8. But these are only a whole number data taps. What about this small numbers such as 5.8 or negative 12.7? Well, we make use of the double data type. We want to be more precise with your values. We would use a double, Especially if you take it into account mathematical sanctions, it will require precise numbers, such as taking the value of pi and giving it to a variable. So we can use it in our programs, will mainly be using double and integer throughout this course that you're going to be more precise. We will also include long, will most likely won't be using bite or short as whether we use an integer for 15 years ranges rather than shortfall, but it won't make any difference to our program at all. That being said, we can create our variables the same way we created the text variables in the previous lesson, such as nt. And the school int. And this time we give it a value of, let's say 50. Note, Nothing is encapsulating this number. Numbers can be left on their own, whereas text must be encapsulated in quotation marks or double quotation marks. And just like before, we can make these variables constant. With that said, Those are some number data tabs. Now we can work with some functions. So I'm gonna create an output line here. In the previous lesson, we learned that you can add text on to other text. And it would read much like sentence by using the operator. However, when it comes to working with number data types, you will find that if we make use of mathematical functions like so, they work with each other and add to each other. So if we add 50, you notice that the double value has increased by 50. So let's try 25, 0.5, and go over the next mathematical operators. So we've done the addition. We can also do subtraction with the subtraction symbol. As you can see, yeah. We can do division with a forward slash. You'll notice it returns a double. And we can do multiplication with an asterisk, shift eight and your keyboard and our program, and it is multiplied. With that in mind. You'll also note that program follows basic math order as well. So it suggests some values here. So you can see that and run the program, it prints 248. This is because multiplication comes before subtraction. If I put minus here and times here, and run our program, it prints 40. So the program follows basic math order. Next, I wanna show you what happens when we use division and clashing different data types with each other. For example, if ours to take this num, int and Alister divided by three. When I run the program, you notice eight prints a whole number instead of a double. Because if a double is not involved in this math function, then it will always output what is the basic value, which is a integer value here. A whole number, very subtle, divide 15 by three and output 16. But if we were to make num int a double instead of an integer and run our program. You'll see it prints out a decimal value like so. So if you want to be more precise of the values in your program, you'll be using double more than integer. Of course it doesn't hurt to use integers where necessary. And in some cases, it may be perfectly apt to use integer of a double. With that said, let's listen has come to an end. Be sure to complete the exercise for this section before moving on in the course. And the next video, I'll introduce you to one more data tab. And I'll show you how to convert one data type into another. I'll see you in the next video. Bye for now. 6. Boolean and Data Type Conversion: Hello and welcome back to a c-sharp programming course. In this lesson, we're going to be learning about the boolean data type and how to convert one data type into another. First, Allow me to introduce you to the Boolean variable as it is one we're going to be using more often than not in this course, the Boolean variable can contain one of two values, true or false. And the early years of programming, this was known as 10. We still use ones and zeros today, but we simply use true and false when we're programming to create a boolean variables, simply tap in bull, give it a name. I'll just call this one test equals true or false. And the next lesson we'll be using boolean variables to create what is known as conditional code. But for now, it's best to know how to create a Boolean variable as you may want to create one in future. But that's said and done. Let's talk about how you can convert data types. You'll find that it is very necessary to convert one data type into another when programming. As when we retrieve user input, we may retrieve a string that is contained and the data that we need to convert into an integer or any other type of data tab for us to use and a program. So I'm gonna be showing you some basic conversions so you can get a good idea of how it works. First, I'm going to show you a conversion that doesn't require anything special. Let's suppose we create a bat variable tab. I'll just call it t equals and I give it the value five presents within range of a, but next hour to place this value in an integer instead. While it's as easy as simply saying equals. In this case. The reason it is this easy is because a bat is in with range of an integer, so far would easily fit into an integer. But if we created an integer value, let's say we took num and gave it the value of 5 thousand. And we trying to make b equal this value. You'll notice there is an error. In this case, there are two reasons. 15 thousand isn't within range of a bird. And the second reason is that you need to convert an integer into a. But the way we do this is casting. Now casting is one of the ways that we'll be learning how to convert one data type into another. And in many cases it won't work. But in this case specifically it will. We can simply take this land that we have here. But before we write the name of the variable on a set of brackets at the tap, bite and numb. Like so. You'll notice that there are no errors here, but you'll still find that 5 thousand is not within range of b as it is a byte datatype. So let me show you what happens to this value. When we try to print it out, you'll see that it prints a 136. Now, this doesn't make any sense scene as we try to convert 5 thousand into a but, but as it is not within range of a, but this can lead to some errors. So it is important as well to keep this in mind when working with different data types such as these. If you have a range that is beyond that of another datatypes range, you cannot simply converted into their data. But however, this does teach us what costing does. It allows us to convert one data type into another as easily as anything. So let's talk about another conversion. Lets say we want to convert a float into an integer. So our prayed a float, I'll call it f num equals. And I'll give it the value of 10.3. Be sure to add an f in front of it. Now floods, so just like decimals and doubles. But in this case, we have to add an F to make sure it works that way. We know this number is a float value and not as simple double lenny. But that's bile A-B-A. Let's cast it into an integer variable. Simply type in int num equals. And another set brackets we tap into within. And we, and we typed in the name of the flood on small. Let me show you what happens to this value when we convert it into an integer. It prints temp. This is because when you convert a float value, beer to double or decimal into an integer value, it will cut off whatever follows after the first decimal point. This means that you can have 10.9 and it wouldn't rounded up to 11 before converting. So in this case we simply get ten as a value. Be sure to experiment with this casting technique with doubles and decimals as well as longs and shorts. So you can get familiar with the rangers and the conversions. But that has more just number data types who have been working with. So let's move on to some texts datatypes. Now, it's very easy to convert anything into a string, but there's a bit more complex to convert a string into an integer. Let's say for example, we have to use a third tab of converting God passing. So let us create a string, could clean and our place a number within, such as 50 and a semicolon to end it all. Now we can simply just cast it. We have to pass it and is two ways of doing this. One is we make use of what is known as the convert class. And this is a bit more complicated as a cause upon a class and a method to convert this string into an integer. It would look as follows. Fname equals convert dot two int 32. And we place the value within Yeah, close with the semicolon, and thus would convert the string into an integer, as we can test by adding five to his value and outputting the result. It prints 35. However, there's a far more simple way of parsing this string into an integer. We simply take out this line here. And this way we simply make use of a simple integer method, int dot pass, like so. And the result is the same. Of course, we stick with integers and don't have to call upon a foreign class. We simply just make use of the integer methods that come with it. Be sure to experiment with this with both floods and decimals, as well as longs and shorts. And finally, to conclude this lesson on converting one data type to another, let's talk about converting anything to a string. We can make it a char, we can write an integer or we can create the float. But for now let's just create a simple number. Make it a double, and give it a long value, such as this. To converted into a string. Simply have your double quotation marks with nothing within them. Plus and the name of your variable, like so. So your font that when I print out this value and the console right plan with plus 55 will not be attitudes value, but rather added at the end of its value. As you can see here. He could do this with any data type and it's just as easy as that to convert it into a string. And with that said, this lesson comes to an end. For sure to practices these as well as the exercise in your workbook. And I'll see you in the next lesson where we will go over if statements and operators. I'll see you then. Bye for now. 7. If Statements: Hello, and welcome back to a c-sharp programming course. In this lesson, we'll be going over if statements and operators. Now in the previous lesson I mentioned, we'll be creating something known as conditional code. This is code that will only run if a certain condition is met. So this allows us to create more complex programs that will take certain data or as instructions and complete a task based on those instructions. But let's simplify that. To create a conditional code, we make use of what is known as an if statement. An if statement, we'll take one piece of data and compare to another. If the condition for that comparison is made, then the data that follows in a set of curly brackets will be executed. For example, let's say I create a basic integer and I give it the value of phi. I then create an if statement by simply tapping in it a set of parentheses. And this is where I'll make use of operators to create a condition. For example, I ask if numb is greater than three. That is the condition for this code. And as you know, five is greater than three. So the condition has been met. But of course you would have encountered some other operators in mathematics are greater than equal to. This then less than and equal to. And for not equals to, we have exclamation point equals and four equals two. We have double equals. The reason we use two equals symbols is because one equals symbol or change the value of that variable to three. But we don't want to do that. We want to compare these two values. Now, when a condition is made, what it does is create a Boolean value, proven true or false, one or 0. And as we know, if it is one, it will be run. And if it's 0, it will not. So in this case, it will create a boolean value of true. Or as our machine will read it one, and it will run the code in the if statement. Now to create this section of code, simply press enter after the parentheses. Create a set of code brackets by simply tapping in first cold bucket and pressing Enter. That's automatically move and indent the code. So this way it's much better organized. You notice a dotted land is drawn here between the two cold brackets. This is to make a much easier to read, as you'll notice of these code brackets having connecting lands as well. And ask simply have a output line two tasks, if this code is working. Addition, is it like so? And now let's create it so that this code will prove true. So as simply say greater than three. And run this line of code and prints this condition is met. So that condition was met and the if statement ran its code. It's as simple as that to great, a working if statement. If a clause is not met, nothing more run within. As you notice when I run the code after changing it to less than, you can create a variety of if statements with different conditions. So let's say we want to create one that will run if the code proves false. In other words, we have occurred that tells us if it works, and a code that tells us if it doesn't. Well, we can simply create another if statement with the opposite and that grows. Let's say, greater than or equal to three. And I'll just copy this up Portland and pasted with a set of brackets and adjust. The app would land like so. So now if I run the code, it, since the condition is not met. So the first line of code did not run. It's fairly simple to use, but we can save us some thinking if we have more complex conditions. If the first condition proves false, but it is a rather complex condition. So creating one that is the inverse may be difficult. And which case we want to make use of an if else statement instead of two if statements. And it would look fairly similar. We simply press enter after this set of brackets, tap and else. And have a set of cold brackets. Just like that. They'll take this code pasted between these set of brackets over here. Save us an additional ifStatement that we don't need. And you'll find this works the same way as if we did have two if statements. As you can see here, you can create many complex programs with proper if statements in place. In other words, you can have are large sequence of if statements working together depending on the data that has been entered. I mean, after all, if statements are used everywhere in our computers today. An if statement is assigned to every key on a keyboard. So that way it tells us if a key is pressed to output that character on a piece of software such as this on a Word document and so on. Even if statements in the time clock in your computer, if 60 seconds has passed, then it will add one minute to the tongue and so on. But that said, that brings this listen to an end. Be sure to complete the exercises on if statements in your workbook. And once you feel comfortable, I'll see you in the next lesson. We will talk about more complex if statements, called nested if statements. And we'll also make use of additional operators. I'll see you then. Bye for now. 8. Nested If and Additional Operators: Hello and welcome back to a c-sharp programming course. In this lesson, we're gonna be learning about nested if statements and additional operators. And the previous lesson, we covered the basics of creating an If statement. We saw its capabilities and we now know how it is used in our computers today. With this in mind, we can create more complex if statements to suit the conditions we want to be met. For example, let's say we have multiple conditions that need to emit. And we want to create an if statement that can work with that. So once more I'm going to create a num value, and I'm gonna give it a value of 35. I want to create an if statement that would check to see if the number's value is above 30. And then I want to create another if statement that would check if it's below 40. And I want both these conditions met before I can run a line of code. Well, I can make use of what is known as a nested if statement to check that our first create a single if statement with the first condition that I want to emit. For example, is num greater than landlord say equal to seti. Create a set of curly brackets just like before. Next, I want to make sure a second condition is made. Well, I'd simply put an if statement within an if statement. This is why they are called nested if statements. It's one if statement nested within another and are put on the next condition, which is numb, is less than but not inclusive of 14. And I'll just simply say console dot, write, line and the message. All conditions met with that written outlets tasted this nested if statement are running the program. Now all conditions have been met as we have a value of 35. That if we have a value of, let's say 25, it prints conditions not mate, and there's a one at the end. So that means it is filling this condition here. And the first else statement, if I change the value now to, let's say 40 or higher, 46. It prints conditions not made to. So the first if statement was fulfilled, so this else would not run. Then this if statement was tested that the conditionals proved false. So this else statement ran and it printed conditions not pit to that is the fundamentals of a nested if statement. And we can have as many if statements within if statements as we want. We can even include if statements and R L statements as well. So that way we can go even more complex. If a condition is not met. However, we can simplify this particular case with what is known as an additional operator. We don't always have to use if statements, and in some cases it may be very necessary that we do. But in this case, we can make use of an additional operator to make sure we check two conditions within one if statement. So let's just remove these lands code here and make use of an additional operator. An additional operator is simply a set of characters that we add after a condition. To tell our if statement that two conditions or more need to be met. Let's set of characters is two and symbols. And then we tap in annexed condition. Like so. So if I change now the value back to 35, it says all conditions met, which is correct. If attention to something below 30, such as 29 and run the code and it says conditions are not met. And if I change it to 40 or valley that's higher. It also says condition's not meet. This is because it knows that one condition is met or the other, but not both of them. As a result of the boolean value for this condition would be false. And it goes straight down to using the console dot write line in the else statement. So he saved us solve some lines of codes and complications with just the use of this additional operator. Now there is a second additional operator that we can make use of the or operator. While this is the and operator. The all operator is simply these two vertical lines or shift backslash on your keyboard. But this whole operation means for this if statement is that if one of these conditions is met num greater than or equal to 30 or none less than 14. The code will run. In other words, if this condition is met or this condition is met, a code will run if both on it, it will still run. It is only if neither are met that it won't run. But as we can see from these two conditions, no matter what value of num we have at will always prove true. Because if one of them isn't met, the other will surely be met. So let's just adjust this. But further, if num is greater than 30 or numb is less than 25. So we have a small window of values that can be used that will run if none of these conditions are met. And that is between 30 itself and 25. So at the moment I have 14. So one of these conditions is met. And it says all conditions meant. If I change it to, let's say 24 and run the code, it says or conditions met. But if I make the value 30, twenty nine, twenty eight, twenty seven, twenty six, twenty five, then none of the conditions are met. And it says condition's not met. Now there are definitely particular cases when all additional operators should be used. And are situations where an and operator should be used. It is best to keep these variations in mind as you may encounter her program requiring you to create a narrative, a statement, or simply make use of an additional operator. But that said, this lesson has come to an end. Be sure to complete the exercise in your workbook and are seen in the next lesson, where we will learn how to retrieve user input. I'll see you then. Bye for now. 9. Retrieving User Input: Hello and welcome back to a c-sharp programming course. In this lesson, we'll be going over how to retrieve user input. Now as you can imagine when it comes to programming, retrieving the user's input is very important. It is the data that we receive, the commands that we get to execute tasks that our programs perform. Scene as it is such an important part of programming, the code to retrieve user input is simple. Much like console dot write line. We have console dot read line. This code will retrieve a user's input and place the value in a variable of our choice. So let's create a string called name and put console dot read line as its value, like so. Now you can do this in any number of ways. You can create the string before and just say name equals console dot read line. But for now we're gonna save on lines of code and just do it in one line. And we'll have a wrap plan as well to test it out. My name is plus name with the semicolon at the end. So let's test out the program now. And as you can see in the console window, we have a blinking underscore, which signifies an intervening data. So I can maintain the name John and press Enter and you see that what is my name is John. So we can now retrieve a user's input for our programs. Now you notice that I retrieved the user input into a string variable. This is because the input that the user gives as always converted into a string as it is, the data tab that can contain any type of character. Whereas number tabs can only contain numbers. They cannot contain letters or characters. We said, said, if we want to retrieve a different Data tab from the user, will have to convert it from a string into an integer or float or Boolean, depending on the type of data that that amount will have to make use of passing to get the values that we want. For example, if we wanted to retrieve an integer from the user, it paid an integer variable. And we'd pass it like so. And within these parentheses will have the console dot read. And that is how we retrieve an integer value from the user. And we can use that type of data. As you see here. When I taste at the line of code into entertain prints 15, which means the string was converted into an integer. With that, any problems, one small, you'll find this incredibly useful when working with if statements, depending on the type of data a user can enter, you can create IF statements that will give a proper response. And with that, this lesson has come to an end. In the next lesson, we'll be going over how you can avoid repeated code with loops. As see you then. Bye for now. 10. The While and For Loop: Hello, and welcome back to c-sharp programming course. In this lesson, we're gonna be learning about loops. Loops are handy sections occurred that allow us to create repeatable code. This way we can save Tom by avoiding rewriting the same lines of code that perform the same task. There are two loops in particular that we're gonna be working with. The while loop and the for loop. Now, loops work very similar to if statements. They have a condition and as long as that condition is met, the code within the brackets will continue to run. So for example, I'm going to be showing you a while loop. I'm going to first create an integer value, and I'm going to give it the value of 0. And then going to create a while loop, simply tapping in while a set of parentheses with the condition. And our right numb is less than ten. And then a set of curly brackets. As long as this condition proves true, the code within the brackets go run. So for example, if I would print out num is value, like so. It will print it out repeatedly. However, there is a flaw in this code. What you'll notice when I run the program, it continuously prints 0 without an end. This is because we needed change nums value in order to make the condition prove false. Otherwise we have a never ending loop. And of course that doesn't work with programs. We need to have the loop end at some point. Otherwise, we're going to have a bogged down program that doesn't go anyway. One of the ways we could do this is by simply changing the value of the line of code is being written, let's say num equals ten, like so. We run the program and early prints 0 once, but of course there isn't much use. We want this code to run a certain amount of Tom's, let's say ten times. What we'll do then is make use of an incremental. This is when we make a value of the integer increase by one each time that line of code is run. Now to create an incremental is simple. We could simply say num equals num plus one. And this will add one to number's value each time that code is run. So considering that it is in the loop, when we run this code, it will run the loop ten times, like so 0 to none. But of course there is an easier way of doing this instead of taking now is very in adding one just like this, we can simply say num plus, plus zone. And it does the exact same job as you can see here. So we have now created a loop that saves us ten lines of code of outputting the value of the same variable again and again. But of course you can use this loop with other conditions. So let us say that we retrieve using input and replace its value within a string. So let's say string name equals console dot read line, like so. This will take a value from the user module in Tanzania. And in the while condition will say while name is not equal to and are put in, stop for capitals than I have it print name, and ask the user to enter another value to continue the loop. So let's run this program. So right now it's asking us to enter data. I can 18 John and prints Jon, Steve, and so on. But when I print stopped and food caps, the program ends and stop isn't repeated as well. So we have now created a loop that will run a certain amount of Tom's depending on the user. This is how we can use conditions. Advantage when working with loops, we need not necessarily make use of a number that make use of data itself and checking to see if certain data requirement is met before in the loop. It could be a set number of names that have been entered. And which case we will have to make use of an if statement to make sure the users into a name and so on. It's loops like these that are used in such basic but important parts of our software. For example, if you're logging into a service engine in your email and password, it will keep checking with a while loop until a certain requirement is met. Let's say you intend a password wrong too many terms that'll be a condition in the while loop. And when that condition is met at all, run something that is you are locked out of the service for a certain period of time. Or perhaps you are signing up to a service and you have to enter in a certain password requirement, like a set amount of characters and number and a character. And which case you will have to have a while loop there, checking to see the password is adequate again and again. So that is a wire loop, a very useful piece of code that allows us to create conditional code repeatedly until a certain condition is met. And wherever we have a second loop, we need to talk about, and that is the for loop. Now the for loop is far more simple as it is just a counting loop, like the first example I just showed you. This time. However, it includes the incremented and the condition all in the same land. So we're tapping for just like we would have Hawaiian lipo statement, a parenthesis as well. And within these parentheses, we're going to include the following. We first create an integer variable. Commonly we use the integer variable i with the inner for loop equals 0. We then put a semicolon within the parentheses after this. After this semicolon, we include the condition, let's say i is less than ten, again, semicolon one small. And then we include our incremental like so. And one small we can have a similar piece of code, console.log plan and we'll print i's value like so. And there we have a basic for loop. We run this line of code, it runs ten times. This is the kind of loop your use. If you have to run code a certain amount of towns, a while loop, you'll mainly use for special conditions. Whereas a for loop is used for running code is certain amount of towns. We said, said there's two more things left to do. One is I've introduced due to an incremental, but we have something called an decremented. But this will do is decrease a value by one by simply tapping in to manage symbols instead of two plus symbols. You notice I run this line of code. It is constantly minusing one from the value that is depicted here. And as you can see, loops ran rather fast as any few seconds had been speaking. It is run at a 100 thousand times. Next, you can have loops within loops, which in many cases you will find is very necessary for more advanced programs. And it depends on the output you want to create. You can create a set of nested loops that work together to output the right output that we need from a program. And in many cases, this will save you so many lines of code that it is very necessary to include it in your program to make it more efficient. We said, said, those are the loops. I recommend practicing the loops. And I'll see you in the next video where we'll be doing the final project for this course. See you then. Bye for now. 11. Final C# Project: Hello and welcome back to a c-sharp programming course. This is the final lesson in this C-sharp goes. In this lesson, we will be completing the final project. So I've gone ahead and started a project. Click.net framework and click Next. And I'll be quiet, ticket tester by Excel and clicking Create with that, then I leave you for a moment to pause the video and create the program yourself. You can find the project in your workbook as the final project. And when you're ready to see the answer and pause the video and I'll begin. All right, and now that you've created your program, I'm going to be providing you with an answer, which you can also find at the back of your workbook. Now the first thing I'll be doing is creating the integer variables that are using it to add the program. First, I'm going to create an integer variable that account the no entries. And I'll give the value of 0. An integer variable that accounting entries. Same thing and a simple counter variable with the same value. But that then I'm now going to create a while loop where it can't is listed. And a set of brackets with our main code will be. Now I'm going to create a console dot write and ask the user to enter. And I'm going to create another variable called age, INT and console dot land. So we can get user input to intend and age. And now I'm going to be checking age with an if statement. If age is greater than equal to 18 plus. And console dot write line age. Just to make sure there's a suitable statement that prints out and an else statement. If statement, like so. And finally, account. So that way this loop will eventually end on Saturday. I'm going to create a simple output to output all the data we need. So that's the no entries. First. Rather suitable statements such as entry. Semicolon. Copy this land based at year, and it's time for the entries, takeaway or not. And finally, we need a percentage of those who are allowed entry. So another LAN brackets in, yeah, I'm going to take the Entry Terms of 20. So that way we get an accurate present. And in a suitable statement once more, testers made into the program, something like that, and close the semicolon. And that's pretty much the entire program. We can enter in the fab ages. So I start with 18, which is entry 20. The same thing. Let's say 1716. And so 40% of the test is made into the program, which is correct. And it is as simple as that was ticket tester program. However, I would like to point out that this is only the most basic on, so one can give for this program. And we can simplify a lot of this code to make it a more optimized program. First, I would use a for loop scene as we are going to be only asking five times. So we have a set number in mind. So we'd create a full int i equals 0. I is less than n. I plus plus. We can then remove the while loop entirely. Next, upgrade the age variable. Outside of the loop in case we encountered an error. And I'm just going to replace these as well. Underscore int. And finally, the final output at the end of the program, we can simplify by making use of basic shortcuts, such as backslash n to start a new line. And we can then take this information and this red line and paste it in here. And we can save ourselves another line of code. And I wouldn't go as far as to take the output from this line and paste it in here. Although we can do that as well. But mainly for neatness sake, I'll have the no entries and entries printed together. And the final output, say in the percentage of people that made it into the program, I leave on a separate red line. So that way it's just much easier to work with. You'll find that this program works the exact way, but it is far neater and shorter, so that's easier to understand as well. But of course, as you learn more advanced lines of code and go to understand the language of it more. You can even optimize this further while still maintaining the neatness in the code. We said, said that is an answer to this course's final project. On that note, thank you for joining me in this course. And the next video, I'll conclude to what you have learned in this course and where to go from here in c-sharp studies. I'll see you then. Bye for now. 12. Conclusion to Beginner C#: Hello and congratulations. Having reached the end of this course and completing all your exercises, you have a beginner's understanding of c-sharp programming was practice the code you have learnt in this course will give you a fantastic logical understanding of programming. It is this logical thinking that I'll help you solve problems when it countering errors or better yet, avoid them altogether. It will help your creativity as well. Putting your ideas for programs into action with sound code. Now, where to go from? Yeah. At this point in your studies, you are ready to move on and study more difficult code. This beginner course has given you the understanding of how code fits together. But there's more to learn than loops and if statements. However, I cannot understate your achievement. You have taken the first and hardest step, continuing your studies, developing ideas for programs and using them to put your knowledge to the test. Thank you for joining me in this course and happy programming. Okay.