C# Programming language | Denis Tatarkov | Skillshare

Playback Speed


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

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

4 Lessons (45m)
    • 1. Interactive Hello World

      11:18
    • 2. Variables and Data Types

      9:32
    • 3. If operator and Ternary operator to avoid division by zero

      10:04
    • 4. Use Loops and TryParse function to validate user input

      13:39
  • --
  • 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.

74

Students

--

Projects

About This Class

In this class you will learn the basics of C# (CSharp) Programming language. Including writing and reading fron the console, declaring variables, classes and functions etc.

Meet Your Teacher

Teacher Profile Image

Denis Tatarkov

.NET/C#/SQL teacher

Teacher

Hello, I'm Denis. I'm a professional Microsoft .Net/C# and Microsoft SQL Server teacher. 

 

In 2016 I got Bachelor’s Degree, in Program Engineering, at Kherson National Technical University.

During 2015 – 2016 I was working as a freelancer software developer.

1,5 years I was employed at DataArt Solutions, Inc., (dataart.com), as Software Developer  

During last year I am working as a teacher at STEP Computer Academy (itstep.org/en/).

See full profile

Class Ratings

Expectations Met?
  • Exceeded!
    0%
  • Yes
    0%
  • Somewhat
    0%
  • Not really
    0%
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.

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. Interactive Hello World: Hello, everyone. In this session, we will learn how to make our first applications have a world application, and then how to make it a little bit more interactive. So assuming that you have installed Microsoft Visual Studio from the visual studio dot com website, um, select the file menu, then you sub menu and click the project among all the project templates. You need the one in the visual C shot group in particular, the console up application. Give it a meaningful name, so you will be able to recognize it even if you have ah, 100 off projects on your computer. Let's name it, you share interactive. How the world Okay, leave the rest of the perimeters by the fourth. I didn't give it a little time to produce these templates. Template allows us to start from something no started from scratch. So we have somewhere to write our code somewhere to start somewhere to begin with. Okay, Andi, uh, let's remove things we won't be needing during this session. For example, the name space declaration and some of the connected Ribery's okay. And in order to have the four month in six press the Control cave, the So this main function is basically the entry point off the application. Whenever you round your application, the code that was written inside of this faction begins to execute. And in order to reach this, have a world sign you would need to the council class and they're using the console, uh, application type, console cross and right on function. Basically, because we need to ride the wine stating, Have a World This function has 19 possible combinations off input parameters. But we need Teoh passages one for a meter on. Since this is a sign we need Teoh, type it inside of the double quarts. You can see them automatically coast for you, then finished with Hello world. Don't forget to put the cynical on In the end of the on and of divine. It's the C sharp Tom Dart. Then you would just press start and wait a little bit because it's the first compilation off the project. You can see that several world was actually printed, but then the program immediately terminated. That's basically because the execution has finished. It has done old dust. It should so in order to keep it on the screen, you were just at maybe so. Briefcase, for example. Come on, That is waiting for the user to press some key. Now, if you want the application, the signs will be printed. And then the program will wait for the user to press some. Um, some key, basically, in orderto inform the user that he should press any key for exit. You just add another line stating so So instead of have a world just, um right press many to exit. Now it's a little bit, um, more user friendly again. Press start, and you can see have a world And the message that you suppress any key. So you exit. Okay, but, uh, this program will basically round violence and the print have a world each time when you started. Okay. Not really interactive. Not really interesting. So let's make it a little bit more interactive. Let's change it. So it say hello and then name off whoever has launched it. Okay, In order to ask user for an input and save it, you need the console. Read line hunks. Um, it has no para meters since it takes an input, and then these input that user has type needs to be stored summer basically inter variable . So since we are asking for a name, let's call this variable name and save whatever dysfunction returns into this variable immediately we get an error because our variable wasn't declared. That doesn't have a type. Basically what type should the from this message books you should BC to the top where you should see from the top left that it returns a string. So basically the variable that stores the result should have the type strings. And now you want to say havel this name. But if you leave it like this, it will be printing hello name every time because it doesn't know that name is actually the variable and not simply a word. In order to read it know about it, you would use the string interpolation, uh, simply put the dollar before the double courts and take the name word into the curly braces . Now you can see it's highlighted into the cover off the variable there, highlighted with grey by the entire list since and whenever you found this application Sorry, five is reserved thing I said breast start instead. So it's no waiting for the input from the user. Okay? We can ride the skill share, and it will say hello. Skew shirt and then type press indicated exit. But let's say that we have launched it while after this lesson was made and we don't know what kind off the input it expects or somebody else simply launched it. Um, we should basically add divine police enter your name. That would make it much more, um, user friendly. So let's copy of the wine with the right line function and changed. Assigned to police. Enter your name, then click. Start there. You have your sign. That's you share the center. You can see the greetings levels, Keisha, and press any key to exit. Congratulations. You have your first interactive application. OK, But all this time we were wanting it from the development environment. Let's say we want to share it with our friend. How do we send this application or what? Say we want to use it Resulted development environment without the visual studio. Uh, you need to simply know where the executable is located. Where this compiled code is located. You would press the right most bottom open containing folder. You can see the four. There is the project. Then you would need to navigate for the reason Aries debug folder. And they have your skew share into interactive have a world application. The second Follies? Not really, but it's not necessary for the execution I want. It is a double click. It says, Please enter your name. That excuse here again. For example, press enter you. You have your greeting, several skills share and the sign press any key to exit. Okay, so it basically, if you pass this executable on another PC, it will also work. But how does this work? Uh, well, basically, that another PC. I need to have these system library. Okay, Um, how would they be? Check if it's in place. Um, for example. Ah, press, uh, on this council class because it's located inside of the system in place after. Well, okay, you can see the the content off this console class, all the functions and properties that it has. But what's more important for our situation is that on top off it, it has the, um, location off the library that contains this class. So basically, you would need to check this past If you have these things than your program will execute successfully and any computer that has these, uh, m s. It most likely stands for Microsoft and core Leap. Most like a stance for core library, which has the ah, system name space inside. So, basically, any PC that has this library will know about the system in a space. I don't know what is the console class, and we don't know how to execute our, um, right line. Ah, read wine and weed gay functions. Uh, and from the past, you can see that this library is inside of the dot net framework library. Okay, so the C sharp and these Ribery are part off the dot net framework that was installed, um, during the installation off your Windows operating system. So basically, if you have the, um, dot net installed on your PC, then this program will certainly work. Okay, so that's it, guys. Thank you. Progressing and let me know if you liked it. And if I should continue these residents, thank you for your attention. 2. Variables and Data Types: have everyone. So doing our previous station be alone. Hard to read and write from the console and slightly about the concept off the variables. Invariable types. So let's get deeper into this topic because they're going to We're gonna use this very often. So let's create new project again File on you, Um, project on against that the console application. Give it a meaningful name since, um, they're going to have a lot of them. So we need to recognize this particular one, for example, would say it's going to be the very bulls Wesam. I don't know. For example, leave the rest by default, okay. And, uh, as, for example, in this lesson, we will write a program that takes two number from the console and outputs their sum subtraction division and the multiplication. Okay, so it's kind of off calculator. So in order to take two numbers from, um, from the console, we would need basically two variables. Okay, thing first console redefining. Remember So read line and being the similar fashion, our second. And let's not forget about user friendly interface. So let's print message. State police entered the first number and police under the second number. Okay, so let's make use of the console right line function and, in fact, that use different ones for this one, so we could learn a little bit more use simple, um, right function, which expects pretty much the same arguments police enter in the first number. And this cynical, um, in the end of the line. And after we asked about the first number, we need to print another message. Please enter the second number how this one works and how these functions are different. Um, for a start. So it compiles and we should see the first Fine, we stay. Please enter the first number. So the difference with the right function, um, versus the right one. Is that your input or basically your second action that follows after this one is present on the same blind? So that's 20. Then we should see the second from state in. Please enter the second number 10 and then terminates because they didn't try anything else . OK, so what we want to have is the output which states the some of these numbers. Okay, console right line. But this one would say the right line and brain from the number he is. And we can make the ah some of operation right in this line. All we need to do is say first loss. Second, remember that once these lines is printed, it will terminate. So we will add console right line stating, um, press any key to exit and the key command, like in the previous session, Let's make it a little bit more user friendly and add the space between the input off the perimeters and the results. OK, That would be, um, empty right mind function without any sign. Now we can see start. It will ask us about the first number 20 second number with a 10. Some of the number is 2010. Okay, We didn't expect that wide happened because basically variable first and variable second are the strings. Okay? And, um, result off making some of strings. Is the concatenation off the string? So 20 past 10. It's not the some off the numbers. Okay? These operations are acting differently for each, uh, data type. So what we need to do is treat them like the numbers. Okay. We need to have them as the numbers in order to convert the user input, which is a string into the number, should make use of the convert cloth. And it has, uh, method two in teacher 32. Uh, dysfunction can take as an input. Um, basically the output off the read wine function. Okay, so we put one inside off another, and now we can make this variable first and in teacher. Okay, which is basically 12345 and rest off the numbers. All right? And basically change the 2nd 1 in this in your fashion. So it was just replaced and renamed this variable Second was the fastest way. Now, if you start them, the user input will be converted from the strings. Think interpretation off 20 and string interpretation of 10. And David will be, um, they will be put together as numbers 20 plus 10 which is equal to 30. Now, we can make use off all other actions and printout. That's a difference. That is correct. His first mine second, then maybe division off the numbers. He's first, second, and lastly, multiplication first multiplied by second along the application. Repeat your input. 20 Tim. And there you have 20 plus 10. 30. Um, plenty. Minus Stannis, then 20 reason by 10 to and the multiplication is to handle it. So now you can see that you have different data types inside of the C sharp. Uh, these data types are treated differently. The operations are, uh, executed d currently for them. And also, you know that you can convert one type into another, using this convert cloths and in case with conversation off strength into the teacher's union to use convert to in Teacher 32 method. This one expects the string value as an input which is supplied from the read line function and eat outputs the in teacher number as a result. Thank you for listening and keep watching. Let me know if you like it. 3. If operator and Ternary operator to avoid division by zero: Hello, everyone. And in this session we will learn the else operator and the turn every operated. So as some of you might have guessed, this program has a little issue. It will crash every time when the second number is zero. So let's actually take a look at it. Start any number as the first number and zero is a second. So it's crashes. Divide by zero exception. Attempted to divide the zero basically because second number waas zero and we tried to make the division. Okay, so how do we fix this? Let's first try to fix it with the, um if operate so basically you want to say ive second number is equals to zero, Then you don't want to make a division. You're going to print out the ever message, right? Console right line. Let's say the division cannot be performed, you know, deeper form. Second number is the euro. But in the other case, everything is fine and you can simply continue with what we had before. Okay, let's try again. So any number can be the 1st 1 And here is it's like so all operations are successful, and instead off the error, we have a message. Division cannot be performed. A second number is zero. Okay, so this is basically how the operator works. You specify the condition, Um, decode that should be executed in case if this condition is true. And the else book, which is optional, of course, the else book will be performed will be executed in case you in these, uh, condition used false. Okay, so it's work. It works perfectly, but a Z can see both books have these council right line function call. Okay. And the actual difference is the message that you want to talk. Basically, this means that we have the duplicate coat on. What we would like to have is these council right? One function, um, written just once. OK, we don't want the duplicate code. So in order to achieve this, we might introduce the variable that will be initialized with the first message in case this condition is true. And with the second message, in case this condition is false. And then you would print out whatever this very built is the story. Okay, this would look like the let's call it division results, and for now, it doesn't have any value whenever the condition is true. You want Teoh, you need devised it with the public method damage anymore. And, uh, if the condition is false, then you want to store the results. We don't need this anymore In the anti. Want to print out? Whatever this thing Variable store case counsel, fight line. It is in the result what? Trying teeth works So any number can be the 1st 0 is the second we have the political will be performed message. Everything is fine. And in case if we supply the correct value But the warm the vision of the numbers is to end . This is correct. But if you take a closer look, it actually took us even more lines of code. Okay? Not what the originally wanted. We wanted to shorten it and maybe simplified. Okay, um in this case would actually can help us is the turn. Every operator and its general syntax is let's use the commentary for it. Um, the condition that you want to look at. OK, leave him. Question Mark, Um, the first statement that you want to execute. Okay, Statement one. But call it like this Cohen and the second statement that you want to be executed in case the condition is false. So very much like the if operator written into the single line. Okay, the the braces are actually optional. OK, you can keep them. Keep it. Thank you. I just advised to use them when you begin right into court. Okay, So more read to do it. So, in our case, how can we use this one? Simply start the assignment, then specify the conditions. The first part. But the question mark the first very that you want to have in case it's true, Colin. And the 2nd 1 Then you don't need all of these. And in order to come and several wise, you have this comment our disaffected find a bottom, and as a result, he will have practically the same. So any number can be the first. Let's specify zero as the second you have. The division cannot be performed in the second number is zero message instead of the error and in case you specified the correct number, you have the result off division operation, and you can even get it off the variable in here because the right line function can, um except deter Neri operator itself. Okay, so copy everything that you have to the right from the equal sign and grace Variable. It'll work. Just find and comment thes line with to back and start and see that it works absolutely the same. So the first number can be any number of unspecified zero, and you have it message instead of the ever. And if you run this with correct number, but they want it works just in the same. Okay, So this is the example off the turn. Every operator. So basically, um, you specify the condition. Okay. Is the second number equal to zero. Pay attention that you need Teoh right to equal signs in order to check the equality. Equality. This is the common mistake. If you write the single sign, it's possible that the second variable will be simply assigned to zero and return true. So you fall into the true Brooke always. Okay. It actually market as ever in this case. But in case with the book, it's possible that one equal sign will be compiled in program will not behave as you expect . Okay, so first you specify the conditions. Then put the question mark. Um whatever code should be executed in case this condition is true. Then come and whatever coats the executed in case if the condition is okay. So during the run time, it will be checked. If a second number zero, then depending on that, we will receive one of these lines, and that wind will be passed to them. Right? Lying function and the function go print this lying to become so for you to. Okay, so this was the example of eternal separator. And the 1st 1 day, if else operator is, um pretty simple. OK, so thank you for listening and continue with continues in the next. 4. Use Loops and TryParse function to validate user input: Hello, everyone. And today we will fix another Easter with this little program. The issue is that currently we don't validate the user input. And whenever the user types in something that cannot be parsed into the teacher, the program fails to run. Okay, so in particular, this convert to in teachers that to function fails to execute. Let's take a look at that. Start our program, for example. We can type in of it. Basically, a letter cannot be converted into a number. So the function will for you to execute. It plays input string. Basically, this thing that we have time waas not correct forward. So basically wasn't a number, okay. And another situation that leads to the same result is when we type a two big number number that in teacher data type cannot, um, store into very able. Okay, basically generates another, they are. And in order to fix this, we will apply in r another method to bars the number and put it inside off group. So the user will have another attempt in order another attempt to type in the correct number. And basically, this will also teach us how to use the books Okay, So another way to parse the number is to use in teacher bunks and side part okay, located inside of the interior structure. And it's called Try Part. So this function expects also input string the same way as the two in teacher to function. So basically, we are passing the same. Okay, read wine. And what is different with this function is that it gives us the number not as the return valley, but as the output terra meter. Don't worry. We will learn those once they get to the function right about now, all we need to know is that it requires us to ride out key words and variable where we want to store our result. And that variable is, uh, our first variable. Okay, first and we are down here. Okay, so this one we don't need basically done, but dysfunction, as you can probably see highlighted right now, it returns bullion okay, bullion, which basically can be true or false. And that body indicates whether the operation off Parsons was successful or not. So, basically, did you get the number successfully, or was the input incorrect? And that is what lets us put, um on these operations into a Okay, so how do we do it? Let's declare declared that Boolean variable that will store our results off attempts to parse that number. Okay, Boolean, um, let's call it successfully access Belene. And, uh, this variable will be initialized with the result off our parsing operation. So if the user type in, uh, the correct, uh, drink and the number was part, then the type R function returns true, and this variable will be any survived. True. Okay, So the last thing that we should apply here is the group itself. Okay, So which group do we want to you? Since we want to allow users to try at least once before we make a decision whether the parson was successful, successful or not, then obviously we should use the do while group and know the viral. The difference is that do while will execute the body off the group at least once, and then it will check its condition. So in C sharp, the do wild group will be written like this do than the body off the start. What we want to have inside of the body is basically are my part operation. Okay. And the check off the condition is nothing else. But while are part successfully variable. And we finish this, uh, the statement. Please send Collins. Ok, let's actually take a look at this 10 and of course, we should make this prompt. Police enter the first number during the each it aeration as well. So basically replace it inside of the body as well. Okay. And let's just give it a shot. How big? Okay, so we have this body of the book started. We have this prompt. Police entered the number, and let's specify something that cannot be in number. Okay, just drink better. Eight. Okay. And it moved to the passing of the second number. Basically, because we didn't invert. The are part of texas for Liam. I'm very ok. Um, so it waas false and we didn't finish this way. You should finish this group once are result off price for separation is true. So basically, we suggest take the conversion. That would be, um fine. Okay. Started again. That's something they cannot be number. For example. Letter A and it promise us again. Police entered the first number. Let's try our second case. that leads who ever some large number and eat a game, Um brings us the prompt. Please enter the first number, which actually means that the include waas Not correct, but we should actually inform the user about it. OK, maybe the user doesn't understand what was wrong with it, especially in case with this number, because it's actually number. Okay, so the user may not understand what is wrong with you. So basically, we want to print a message. Please enter the correct number that estranged from minimal value that Inti Jerkens store remarks. Okay. And it would be done. You know, this fashion, we would use our else condition. Actually, in this case, it would be just condition and specify basically in the same condition. So if it wasn't part of taxes, okay with take the inversion in this case as well, then we want to bring come so right line and bring the message that, um the input was not correct, was not all right. Police base. If I number between and in here, we will actually bring what is the minimum. And what is the maximum value that an individual can store? How do we do it. First, let's switch this string to the interpolated string just dollars time. And now we can use expressions and in order to print out the minimum value we have in teacher dot minimum value. So between this and in Teacher Maxwell that no clearly let the user know what he should as an England. Okay, let's give it a shot if we leave everything correctly. So in case with the numbers, we have this situation. The input was not correctly specified. The number, and here we can see. What are the what is the range off numbers that can distort inside of the teacher data time ? We will take a closer look at what can be stored into in teacher what can be stored inside off the other data types in a separate session. Because that is quite alone. Okay, s for now. Let's get back to our input and verify that the situation with a to be number, which is over then two billion and 147 millions and see if it behave the same way. Okay, We got into the same, um, message that let the user know that he made the wrong input and this also, um, shows that they are group works just fine. And you if we type the correct number, we had to the second problem police into the second number where we can type in, for example, 10 and see that the rest of the program works just before just, like work before. Okay, so everything works just as we expected with the first number. Okay, but, uh, closer that we didn't modify the code for the second now, okay. And actually did this would require us to copy this entire piece of code duplicated and shifted to parse the second in teacher variable on a Z result. You might have guessed that this will lead to a lot of duplicating gold. Okay, let's actually take a look at this home. Probably accident duplicated. Okay. We didn't need one making coping. Then we need to change our message stating police entered a second number. We can use the same very able indicating or successfully. Okay. This one shouldn't require any change. Then the message about ever remains the same. And, ah, what else would we also need to change? Is the second number right here. So the message ever message people has gone, so it should work properly. That's for now. We'll give it a shot. So we already know that the first number gets validated. Kevin. Get the message. Typing 20. Not correct. And now let's provoke. Let's try to provoke a never with second number and see if we get the same government. Yeah, it works, just expected. And now we can supply the correct value. It works just like before. And what we ended up with is this duplicating beef off coat, which is not good at all. In this case, In order to fix it, we should make use off the function functions. Okay, so let's leave it for our next session. That will be about using the functions or in C sharp, correct, same method. So as for now, that's what we ended up with the next sessions. Uh, thank you for watching and have a nice day