C# Programming: The basics and more | Programming Made Easy | Skillshare

Playback Speed


1.0x


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

C# Programming: The basics and more

teacher avatar Programming Made Easy, Software Developer

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.

      Welcome to this course! :)

      1:29

    • 2.

      Your first C# program

      3:19

    • 3.

      Data types

      4:53

    • 4.

      Comments

      2:36

    • 5.

      Functions

      6:14

    • 6.

      Casting

      4:12

    • 7.

      Arrays

      6:20

    • 8.

      Lists

      4:11

    • 9.

      String class in C#

      7:39

    • 10.

      Working with files in C#

      5:05

    • 11.

      Object oriented programming

      3:47

    • 12.

      Constructors

      3:00

    • 13.

      Inheritance

      2:58

    • 14.

      Exception handling

      4:50

    • 15.

      User defined exceptions

      4:26

  • --
  • 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.

139

Students

--

Project

About This Class

C# is a beautiful cross-platform language that can be used to build variety of applications. With C#, you can build mobile apps (for Windows, Android and iOS), games, web sites and desktop applications.

Once you master fundamentals of C#, you'll have lots of options in front of you. You can choose to build mobile apps if you prefer, or you can change job and work as a web developer or even implement your very own game. As long as you know the fundamentals well, switching to different technology stacks is pretty easy.

There are plenty of free tutorials and videos that teach you C# and they are great if all you want to learn is C# constructs. But if you want to learn C# and become a better programmer with a bright future and lots of options, this is the course for you. For every topic, not only will you learn the whats, but you'll also learn the whys, and hows. You'll see common errors that pop up as part of developing applications with C#.

I look forward to having you as my student and sharing with you all that I have gathered along the years of practice, hard work and listening to my own mentors.

Meet Your Teacher

Teacher Profile Image

Programming Made Easy

Software Developer

Teacher
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. Welcome to this course! :): Hello guys and welcome to this C programming class. My name is Alex and I'm a software developer that is currently employed and working with C-Sharp for the past three years. In this class, we are going to run through all the features that C-sharp has to offer, starting from data types and going through comments, functions, arrays, and even notions about object-oriented programming. So by the end of it, you are going to be fluent in these programming language. This class is created for anyone that is looking forward to better themselves at writing C Sharp code. And no actual prerequisites other than a computer and an Internet connection are required to sign up and start this class. As far as the class project goes, students that are going to take this class will make a pretty basic C-sharp Project. Nothing very hard, but it will run you through the notions that I will present you in this course just to make sure that you coded them by yourself at least one time. So if I set sounds interesting, I look forward to see you in the next lecture. Let's get started. 2. Your first C# program: Hello guys and welcome to this lecture where I will show you how to start called Inky Visual Studio Code, C-Sharp code. Of course, the anti-type deterred going to use here for decisions. Go deeper. We're going to write yes, Visual Studio Code because both of them being Microsoft property, they integrate with each other and ran smoothly. I don't know it DTP spot, you need to download Visual Studio code. So first of all, the IP extension that is called C-sharp. And when I installed, it was installed to a lot of stuff. And then we said that I don't have dotnet SDK five installed and retreat to get me to a lame, I follow that link and it took me in right here. So I would call install for Windows, installed it. It's basically pretty simple wizard that you get no CO2 and D3 install dotnet SDK. And then Visual Studio, you can open a folder which you are going to create this tutorial. So let's call it tutorial, and then click on Select Folder and it will open up Visual Studio Code. It only has this tutorial folder here. And then you can go to View and terminal and then document. And put this field to, it will open in your tutorial falter, basic C-sharp solution between spawned a bunch of different folders from props in packets and the SES brushed it. We'll have the framework and property groups in it. Again, the C Sharp code called the program, which will have the main function. As you can see right here, it's being done tutorial. You've called this. You can see that it says adult world. So the program compiled successfully. Now, a few subjects that we will touch with the scores will be fundamental data types, arrays and strings and engender wrote working with text, then files manipulation. Then we will jump to the top. But object-oriented programming. Explain some topping Slack class adopt shapes and methods and so on. Also how we can use those C-sharp. And we will also take a look at exception handling core of very nice and error-free code. So in short, we're going to understand how these programming language works. Now we can build powerful applications. We do, whether we are talking about came security key or web pages, ASP.net. I look forward to seeing you guys in the next section, some lectures. 3. Data types: Hello guys and welcome back to this course. In this lecture, we will talk about the two pipes in C Sharp. So what data type specifies the size and byte buffer variable values? It is important to use the correct datatype for the corresponding variable to avoid barriers to sleep time and memory. But it will also make your code more maintainable and treatable in this script that you see on the screen right now, I declared a bunch of variables of different types so we can see what each of them are used for. Main me, several bits get through them. Each of them, and what it does in the main function. First on line nine, integrate might num int I assigned to be the number 5. The integral type can store whole numbers. In general, the input data type is the pre-cracked. Think that type when we create variables, numeric value. Next on the line, then I declared a long number. The known data type can store whole numbers as well as the ENS number. But it is used when the input is not large enough to store it to failure. Also, a note here would be that you have to bend your number. It would be L. So does the compiler know it's a long value? And then moving on to the float that I declared on line 11, we should use the floating point right now for you need the number with the decimal, such as either no, night length, 99. If flow to datatype can start fractional numbers, and you should always end it with that big F. Next, we have to double, that is a floating big point, the datatype as well. And you need to end it with the, although it is not required in this case. So when you might ask yourself if you should use float or double when you have a number like 5.75. Well, the precision of a floating point clearly indicates how many digits to value can have. After the decimal point. The precision of float eats only six or seven decimal digits. While that look variables have a precision of about 15 digits. Therefore, it receiver to use that book from most calculations, movie Gone 19, 13, I declared a bowl or a boolean, and then assign to it the value to a Boolean data type is declared with the keyword pace yourself and cannot meet the negative values true or false. They are mostly used for conditional testing, like if statements, whiles for us and so on. Basically you would declare a value that's true or false, and then update its value along the program. And then check its fair value. And use that value to decide if you want to execute the portion of code like that, or for how long you want to execute the next, I declared a character that's chart. My letter in that gave eat the value D. The char data type is used to store a single character. And the character vast be surrounded by single quotes. As you can see right here. In fastly, students, I declared a string called 915, called it my text. String data type is used to store a sequence of characters. And they need to be surrounded by double quotes. So that's the main difference between character strings. The fact that the character needs to be surrounded by single quotes around the string needs to be surrounded by double quotes. You need to pay attention to the base as it can cause a lot of errors. And the time I struggled a lot with these very legal thing, that always mean a lot of problems because I didn't even see that that was the problem. So then I wrote a bunch of console right lines to write all these data with the extension then the initialized on the screen. So we have to look at it. If we run this code, you can see the values are printed on the screen. And it works very good. So t-shirt that main big pipes that are available in C Sharp. Next two are going to take a look at the comments functions, and so on. So stick with me to find out more about those topics. 4. Comments: Hey guys, and welcome back to their scores. In this lecture, we will talk about C-sharp comments. As you can already see on the screen, that these on the screen comments and is in most programming languages are used to explain C-Sharp code and to make it more readable. It can also be used to prevent execution when testing alternative coater. There are two types of comments. There are single-line comments. You, there are multiple line comments. Single-line comments start with two forward slashes, and as you can see on line 9, then between these two forward slashes, then the end of the line is ignored by C-sharp. Eight k would not be executed. Then we have the multi-line comment that start with a forward slash and a star and hand weight down into its first order. Anything between these two sequence of characters will not be fixed through DWB.org to play C sharp. So it is up to you which one to use. Normally for a short-lived comments, we would use a single line, Carmen. And for a longer comment, you can use a multi-line one. Also. A rule of thumb here would be that your karmic should not be equitable, meaning that it gets to the right part of the screen. So the user or the programmer needs to read your code. We'll have to scroll up in the right part of the beach so you can see the whole element. So if your appointment instead, you can basically split it like the one on line 13. So this is pretty much with the comments. They are chest explanations of the code or observations for you for each lining of the code and so on. You can basically write income, anything related to the code. It will not be executed and it will remain there. For further reference. Thank you guys for sticking with me to the end of this tutorial. And we will move on next to functions in C Sharp. So see you there. 5. Functions: Hello guys and welcome back to this tutorial. In this lecture, we will discuss C-sharp functions or another name for them. In a more object-oriented programming context would be methods. So what the method? It's a block of code which only runs when it is cold. So just like a function in procedural programming, you can best data to eat known as parameters. And methods are used to perform certain actions. You might now ask yourselves, well, why use functions instead of writing the whole code in the main function? Well, the thing is that when developing code at a larger scale, you will have portions of codes that need to do a certain task. And also that there needs to be run more than words. So to keep it clean and reusable, though, defining the code once if use main times C Sharp crisp methods. Now, to create the method, you have to keep in mind that it is defined with the name of the method followed by parentheses. C-sharp provides some predefined methods which already are familiar with, such as Main that is declared in this script that line 32. You can also create your own methods to perform certain actions. To call a method or to execute it. You need to write the method's name in the main function or wherever you wanted to call it from, fathered by 2 parenthesis and this semicolon. You also need to give it parameters method with parameters. You can see here, I declared a basic method with no arguments whatsoever on line seven, and I call it from line 35 in the main function. What this function does is it instantiates an interger x, gives it the value five in their returns data. Furthermore, when it is called, you print its result as output. Also. This image right here specifies that our function returns the date, the type of type int. And as you can see, the datatype that I created, the subtype in the elite is returned. If I, I would have returned a string right here, it would have been an error. Also, the static keyword means that the method belongs to the program class and not an object of the program class. We will learn more about objects and how to access methods through them. Later in this tutorial, we will talk about object-oriented programming concepts. Now moving on, I declared operand. A method with parameters on line 16 that is called GetString. Now, we've method parameters in C Sharp information can be passed to the method as parameters. These parameters excess variables inside the method. They are specified after the method name inside the parentheses. You can add as many parenthesis as you want. Just separate them with a comma, basic CRM 2126. When a parameter is passed to the method, it is called an argument. You can also have a default value for this argument by writing an equal and then the default value after writing that parameter in the parentheses of the function. So here I declared a GetString function that returns a string and pass a parameter that's x. If, when calling this function, we don't specify any parameters, the parameter x would be defaulted to this string right here. Furthermore, what this function does is add the word world at the end of the string. So as you can see, I call it from right here with the parameter halo. So the string parameter one B defaulting to this string. What this function will output will be Hello World. Function can also return void, meaning that it doesn't return anything. If you end up method to return a value, but you can use a primitive data type such as eight double steady string, as you can see on this script right here. Furthermore, we can dock in C Sharp about method overloading. You can see the function 2126 look very alike, but can you see the difference between them? So we'd method overloading. Multiple methods can have the same name but different parameters. So they can have the same name and the same number of parameters, but their type must be different. They can also have different number of parameters pieces called method overloading. Now, C-Sharp will automatically know when you call this function, which one to call. Because as you can see right here, we call the plus method function with the parameters of type double. So it will melt to call this function. But if we would have called it with int parameters, intuitive now to call this function right here. So this is how overloading on methods work in C Sharp. Thank you guys for sticking with me to the end of this tutorial. And we can move on to casting in C-Sharp. So I look forward to seeing you guys there. 6. Casting: Hello guys and welcome back to this tutorial miss lecture. We will talk about C-sharp typecasting. So typecasting each when you assign a value of one data type to another datatype. And in C-Sharp, there are two types of casting. Casting that happens automatically. So you will convert the smaller type to a larger type size. So you can convert a character into an integral. I mean, to go into a long, long int or float, float into a double. You can also do the explicit casting, which happens manually. And that is converting a larger type to a smaller size type. That would be converting the dopamine to a float, a float into alone, belonging to an int, an integer into a character. So going over to implicit casting, casting keys tag automatically when purchasing a smaller size type to a larger size dipole. So as you can see from line 10, we have an interpreter called Mark and assign it the value 19. And then we declared a variable called my tuple and we assign rate my int. And this will automatically cast by int to a double when giving my double the value of myInt. Next, explicit casting or manual testing must be done manually by placing the type in parentheses in front that value. We can see on line a theme that I declared the my dipole, dipole datatype variable in the sine 3.789. And then I declared an int, my int 2, which is a smaller identifiable. And I assigned, it might double, but I had to explicitly cast it, might double to an integer. The Stan by writing the data type that you want. Explicit cast to B2 in-between parentheses. And what this will do, it will assign mind to the number 9 without whatever each after the floating point. And as you can see in the comments right here, and in a second canal will discount. Lastly, we can talk about type conversion methods in C sharp because it is also possible to convert datatypes explicitly by using built-in methods such as comfort to Boolean, convert to double, convert to string, convert to int 32, and convert to int 64. So as you can see from mind, 28, grind declared them integrate dopamine double. And we can convert the integer to a string. And it will have yesterday output that Dan as a string. We can also convert them into a tablet and it will be 10 dot 0. You can also convert to double into an integer and it will be five. And you can also convert the pool into a string and it will be trained to. You might now ask yourself, why use conversion? Well, many times there's no need for type conversion, but sometimes you have to wear and working with user input. So now running this code, you can see all the corresponding values printed as the output. Thank you guys for sticking with me, clipping and texture. And I will see you in the next section. 7. Arrays: Hello guys and welcome back to this tutorial. In this lecture we are going to discuss C-Sharp of race. Race are used to store multiple values in a single variable. Instead of declaring separate variables for each value. Natural observation here would be that the values that are stored in an array would be of the same type, even though you can declared that type object and you can place in that array multiple types of objects. We're going to discuss more about objects when we will get to the object oriented programming part of this tutorial. But for now, we can focus on the syntax of declaring an array in C Sharp. So to declare an array in this programming language, we can define the variable type with square brackets and then its name. Now to insert values to it, we can use an array literal, so we can place to fail using a comma separated list inside curly braces. As you can see the dt it online. When I declared a car's array of strings. And I initialize it for our names. In the same way we can create an array of integers, as you can see on line 28. But instead of strings, we initialized it with numbers. The same way we can do an array of floats, doubles, characters, and pretty much any data type that you can think of, even the y's do to create structures or objects of certain classes. Now to access an element of the array, you can refer that by eating index number, and that's the way you access it. So as you can see on line 12, I access the first member of the cars array. You have to keep in mind that these arrays are 0 based, meaning that they don't start the counting from one but from 0. So 50 would be carriers of 0, BMP cars of one for the cars of two, and then last up cars of 3. To change the value of a specific element, you can reflect that index number and then assign to it a different object of the same type that you want to. On line 13, I assign the first element of the array, cars, apple instead of 50. And then I print it on the screen so you can see that the change happened. Then v2 it. Now we need to collapse to the length of an array. You can find out how many elements in array has a C-sharp using the length property, these will be extremely useful when you decide that you need to loop through an array. You can loop through an array elements with the for loop and use the length property to specify how many times the loop should try. As you can see, our ATP that on line 17. So I made a loop that goes from the index 0, from the index of cars dot length. But it actually goes to cars dot length minus 1, because being zero-based, you have to go to the length of the array minus one. And then I write to the screen for each index, the other method that index. You can also do this with the for-each loop, which is pretty similar. So I did not go into it right now, mainly because it's a bit of a base here syntax. And you need to focus on the more complex implementations and the correct ones before jumping into debt. For the, for each method would be easier to write. Visiting that would not require a counter and would be more readable. But the for loop looks a lot like C plus plus and that's a useful programming language. Do. So why not? No one syntax that can apply to multiple programming languages. Next, you can also sort arrays. And while there are many methods available for sorting an array, the sort method is the most, the one. It sorts an array of medically, if it's an array of strings or characters, or in ascending quarter, if it is an array of numbers. Basically see, I already sorted the array cars on line 22. So the syntax goes like a dot sort. And then as the only parameter, it S for the array that you need to have sorted. So in our case, cars, in our context, it will sort these for current names, even ascending order. So it would be like BMW, then Ford, then master, and then opal. Lastly, you can also use system.in, but not before you write it using System.out link because otherwise it will not recognize all these functions that are already implemented. And you are going to use a system that contains a wide variety of useful array methods, such as min-max and some that are already implemented as I've already said. And it will be very much easier for you to use them that way when running this script. You can see that first it rides to the output, the first index of this array that is 50. Then it writes apple S. That's the first entry that we override right here. Then for the next four words, it will basically just output array. Then it will sort our array and output debt. And basically it will output the length of these intermediates for then the maximum way, anything which is 40, the minimum in it, which is 10, and then the sum of 10, 20, 30, and 40, which is 100. So that was a broad overview on arrays in C Sharp. Next, we are going to move on to this in the next lecture. Thank you for sticking with me and I'll see you guys there. 8. Lists: Hello guys, welcome back to this tutorial. In this lecture we are going to discuss the C Sharp least glass to list class in C Sharp represents the least of objects which can be accessed by index. It comes under the system that collection dot generic namespace. So as you can see in the script on the screen, we declared the system dot collections dot generic name-space. On line three. We can add, revise it with nothing. Now, what we need or any of its fields are the least class can be used to create a collection of different types, like integers, strings, and pretty much any object of any class that you will create. The list class also provides the method to search, sort, and manipulate lists. And that is the reason why it's a very useful class for manipulating simple but also complex data. Now, a few bits characteristics would be that it's different from D arrays because it can be resize dynamically whether curious cannot be. The list class can also accept null. So fairly value for reference tags. And it also removes duplicate elements. If the current becomes equal to capacity than the capacity of the least increase automatically by relocate the internal array. The existing elements will be copied to the new array before the addition of the new element. For this class is the generic equivalent of ArrayList class. By implementing the IDs generic interface, this class can be use both equality and order being competitors. The list class is also not worded by default and elements are accessed by zero-based index. Also, another thing to be noted here would be that for very large decrease chapter two, you can increase the maximum capacity to 2 billion elements on a 64 bit system mindset into enabled attribute of the configuration. And I'm going to tune in the runtime environment a few of the properties that a list has would be the capacity that gets us has the total number of elements, the internal data structure. It can hold it down to its size into the count property, which gets the number of elements contained in a beast, an item that gets basically an int 32 in the excellent lease property gets resets the specific index. And a lot more methods such as add, that it's an object that at least EPM Does the least clear, that clears all the list, contains. It, picks an object and that object keys, array, find, index, remove, remove, index, sort toward wearing, and so on. On the script that I've written on this green wave first declared on line 12 a list of integers called first list. You can see that the syntax for that would be two declared at least and then also give it a new object of type list here. Then on line 15 to 18, we add to our array the numbers 1, 2, 3, and 4 on line 21, you can see that we use the capacity member, which tells us what is the internal number filaments that this data structure can hold without resizing. On line 24, we print on the screen how many elements the array has. Then we add two more numbers. Then we print two fields of our array again. And if we run this program, you can see that first the capacity scoring, the count is four, and then the capacity is six. And the counties 8. So these would be about o with least in C Sharp. Next, we are going to move on to strings in C sharp. So I'm looking forward to seeing you guys there. 9. String class in C#: Hello guys and welcome back to this C-sharp course. In this lecture, we are going to discuss C-sharp strings. As you may already know, strings are used for storing text. Stream variable contains a collection of characters surrounded by double quotes. You can see that you can create a variable of type string and assign me to value. I did that online. There. I declared the greeting variable of type string. And they're assigned to eat the text Hello or streamed in c-sharp is actually an object which contain properties and methods that can perform certain operations on strings. For example, the length of the string can be found with the length property. As you see, I did that on line 14. After I declared a string with the name of text, very assigned it parent alphabet. I been printed on the screen. It's length after the text, the length of the TXT stream is. There, of course are other methods that are available for strings. For example, we have here to upper to lower, which returns a copy of the string converted to upper and lowercase, respectively. As you can see on line 19 and 20. Also, we have the index function that returns the integer index of where these character can be found in the string, that cost function. And those. So the substring function, which takes an integer and returns our string from that index to the end of it. Next we have string concatenation. The plus operator can be used between strings to combine them. And this is called concatenation. Here we have the firstname string, that's John, and last name. That would be though, because it's the substring of chart pass, that's the index of the IEP goes from D to D. So name two would be FirstName, LastName, meaning john, space though. And then we write that on the screen. As you can see, we already did concatenation on line 14 when we printed the result of the length of the string. Of course, there is another method to concatenate two strings then that would be with the concat method of C Sharp. But we're not going to get into that because this operation with the plus is much simpler and much handy at all times. We also have a thing called string interpolation. So now digital option of string concatenation is string interpolation, which substitutes the value of variables seem to placeholders in a string. Note that you don't have to worry about spaces, like with concatenation. So you can see that we assign to the string name tree that we just declared the string My full name is, and then we included firstName and lastName in-between curly braces. So this trigger will be my full name is John Doe. Also note that you have to use the dollar sign when using the string interpolation method. This string interpolation was introduced in C Sharp version 6. Next, talking about strings and its characters. While you can access the characters in a string by referring to the index number inside square brackets. So you can see that on line 44, hi axis, the age in mastering by accessing the 0 index of the string. You have to keep in mind that these strings like arrays and lists in C Sharp, and pretty much any programming language are zero-based, may mean that they start from the index 0 and not one end and not to the length of them, but to their length of their minus1. Now we can talk about special characters, because strings must be written within quotes. C-sharp will misunderstand the string and generate an error. Because if we call, we are the so-called Vikings from the north. And you want to include double-quotes inside our double-quotes. C Sharp compiler will understand that. Here is the ending of the string when it sees another pair of double quotes. So what can we do to avoid that? Well, we can use the backslash escape character. So the backslash escape character turns special character, like double-quotes into string characters. So the C Sharp compiler, you'll know that that's still a string, then we will not endure string there, thus causing an error. So we can do this escape character thing with the backlash escape character for maiming situations. First of all, with a single quote. So if you want to have a single quote inside of your string, you need to have a backslash before it. So the compiler knows it's part of your stream. Them again on double quote and then again on backslash. You'll have to have another backslash before. Of course here, we can talk about other useful escape characters in C-Sharp, such as backslash, backslash t and backslash b, which when you include in a string, we'll give you a new line at the hip, respectively back that space. If you want to say we are the so-called and then on a new line, have Vikings from the node. You must type here. The backslash add character. And the compiler will automatically have the rest of your string put on a new line. Lastly, I would like to show you the difference between adding numbers and strings. As c-sharp uses the plus operator for both addition and concatenation. So you have to pay attention here because numbers are added and strings are concatenated with the plus sign. So if you add two numbers, let's say 10 and 20, 32 integer variables and assign them to a third variable of type integer. The result will be there's some, some tare plus 20 will be 30. The integral z will have the value 30, which of course is an integral. But if you add the same numbers but in a string format. So we declared two variables of type string. First it's a 10, and secondly it's a 20. But in between double quotes, when we declare a string and assign the sum of these two strings, what it will do, it will give you 10, 20 high as it will concatenate them. And as we discussed above, thank you guys for following this tutorial on strings. And I look forward to seeing you in the next tutorial. 10. Working with files in C#: Hello guys and welcome back to the C-sharp tutorial. In this section, we will talk about C-Sharp files. So C-sharp provides us with a way of working with files in our C Sharp scripts. The file class is used, in this case, entities from the system dot io namespace. You have to include that namespace at the top of each script where you want to work with files. So the file class can be recognized. This you can see on the screen I've already included this library online to this file class has many useful methods for creating and getting information about files. For example, we have the method append text that appends text at the end of an existing file. We have the copy method that copies a file. The create method that creates or overrides file, the delete method that deletes a file. The egg cysts method that test whether the file exists or not. The red alt text method that prints the contents of a file. The replace method that replaces the contents of a file with the contents of another file. And the right all text method that creates a new file and writes the contents to it. If the file already exists, in this case, it will be overwritten. Now on the screen we have our basic script of writing and reading from a file. We can see that at nine electron, we declared the stream and the sign to read the Hello World text. Next on line 12, we call the file class with the static method of ripe old text. Because as you can see, this method belongs to the class and not specific object instantiated from it. And this right top text function takes two parameters. First is the path to our file, and second is the string that we want to write to this file right now, given the fact that we don't have the farming that dxdy in this tutorial folder, we can see that after running this program it will create the template will also Right the Hello World text in it, given the fact that we just gave it as the first parameter, the name filename dot dx, dy, that is the path to it. It will basically create our folder at the same pet from where we are executing this query. So the tutorial folder, we could have given a whole path for this text file. If we wanted to create it, for example, on desktop, it would have been C and then users, and then your user and their desktop, and then the name of the file, and it will create that file on your desktop. And laughing along Nine, 14, we declared another string and we assigned to eat file that read-aloud texts from finding that dxdy. Again, the fire class calls the Static Method 3 dot txt that takes one parameter, and that is the name of the stream query you want the text read from. And all the texts from that file will be put in the Read text stream that we declared. And next on line 15, just to make sure that it all worked out and the script had no errors. We outputted on the screen the contents of the text stream. If we run this program, we can observe two things. First, that the finding Ksp text file has been created in the tutorial folder at the same Beth where the program.cs is, that this text file has the text Hello World being eaten as it should have. Because we called the right alt text with this file name and the text Hello World. And then you can also see that our script output, Hello World. This is the text that the thread from this founding dot TXT and then printed on the screen. This would be a broad overview on working with files is C-sharp and I think it's a pretty good place to start reading and writing from files. Of course, you can do more complex operations with more complex data types that you create when working with files and saving them there. Thank you guys for sticking with me to the end of this tutorial. I'll see you in the next one. 11. Object oriented programming: Hello guys and welcome back to this C Sharp tutorial. In this section, we are going to discuss object-oriented programming in C sharp. And more specifically than that, I'm going to give you an overview of 00 00, 00, 00, 00, 00 00 paste. And for object-oriented programming, procedure programming is about writing procedures or methods that perform operations on data. While object-oriented programming is about creating objects contain both data and methods, object-oriented programming has several advantages over procedural programming and debt is the main reason why it's more used. It is faster this year to execute. It provides clear structure for the programs. It helps to keep the C Sharp code dry, meaning it doesn't repeat itself. And it makes it also easier to maintain more defined debug. And it also makes it possible to create full reusable applications with less code and shorter development time. Let's talk about classes and objects. Classes and objects are the two main aspects of object oriented programming. Class is a template for objects, and an object is an instance of a class. That's why we say we instantiate an object from a class. When the individual objects are created, they inherit all the variables and methods from the class. So for example, a class would be a fruit, and some objects of this class would be an apple and pineapple, Strawberry. Also a class can be a car. And the objects that we instantiate from this card class would be fall for Audi or BMW. Or everything in C sharp is associated with classes and objects. That's why it's very important topic in this programming language and you need to have it very well understood. For example, in real life occurs in an object. The car has attributes such as weight and color, and methods such as driving break. A class is like a blueprint for creating objects. As you can see on the screen, to create an object of class car, specify the class name followed by the object name, and use the keyword new, instantiate, the dynamically created the object of that class is typo on line 12, the C-index where these we have the class car and then declare my LBJ from object of type car. And of course it's color will be blue. Color is hard-coded here. Note that we use the dot syntax to access variable fields inside the class, as you can see right here. So to access the field color from the object of type car in it, that object's name, that the field that you want it accessed. You can create, of course, multiple objects of one class, but they just need to have different names. You can also create an object of a class and access it in another class. This is often used for a better organization of classes. Also, if we have a method for this class, we would access it with the dot operator as well. So I think this would be offered the overview of object-oriented programming. In the next sections, we are going to talk about different concepts such as inheritance, polymorphism, and also class members and constructors. Thank you for sticking me to the end of this tutorial and I hope to see you in the next one. 12. Constructors: Hello guys and welcome back to this tutorial. In this lecture, we are going to discuss C-sharp constructors in object oriented programming contexts. But constructor is a special method that is used to initialize objects. Yet furniture for constructor is that it is called when an object of a class is created. It can be used to set initial values for fields or declared the new keyword so they are instantiated. Note that the constructor name must match the class type and it cannot have a return type like void or ink. Also know that the constructor is called when the object is created. All classes have constructors by default. If you do not create a class constructor yourself, C-sharp creates one for you. However, then you are not able to set initial values for fields. Constructors safe time. Baking also take parameters which you are used to initialize fields. And then when you declare your object, you can give it specific parameters to instantiate the fields width. As you can see on the screen, we have the same car class and we detect for it a custom constructor that initializes the model field of the class car with the hard-coded string of Lamborghini I. Now, if we declare this car object and write to the output its model, it of course will be memory king. But now suppose human to have each of your card that you declared a different model type that T1, T2 right from the keyboard to initialize it. Well, forget it. You will have to give your custom constructor parameter of type string, that would be the model. And then you will have to go like this dot model equals model. What this means, the instance of the class that cause these constructors. So this dot model, meaning the field model of the object that is calling this constructor when initializing will be equal to the stream model that is received as the parameter. So now as you can see, when we declare our car, we can specify this string that will go on to be pressed. Sds cars, model field. This would be the way for your constructor to have parameters. And the advantage of this is that you of course, can give custom values of the fields of each object that you currently create. This constructors, of course, can have as many arguments as you would like to give them. Not just one. And of course less car can have a lot more than one field and can have methods that do stuff just like functions with do on their own. But this was the C Sharp tutorial on constructors. And I look forward to seeing you guys in the next tutorial. 13. Inheritance: Hello guys and welcome back to the C-sharp tutorial. In this lecture, we're going to discuss the inheritance process that takes place in an object oriented environment. When talking about inhabitants, we have to think about tweak these that take part in this process. That the right and base class in C sharp, it is possible to inherit fields and methods from one class to another. Group that Harrington's concept into two categories. The TAP class, that was the digraph class, and the class that inherits from another class, the parent class, let's call the base class. And it is the class being inherited from to inherit from a class. You can use the double dot symbol as you can sell 915, where class car inherits from the class veto. In this case, the vehicle is the base class and the car is that you write class. Well, if we look on the screen, you can see that I declared a vehicle class that I gave feel the brand and ebook that a hard-coded print on that card. And then I also got a method to it that basically just outputs the word hawk when cars honking. Now I declared the class did. It's derived from the basis vehicle and it also adds another field to read that's called the model name. So any card has a model name, but the vehicle does not have a model name. A car also has access to the hunk method and also to the brand field as it inherits from the vehicle class. As you can see in the main function when we declare our car, you can see that it has access to the Han Record him, you could call it, and also to the both of these fields that can be outputted on the screen. Now you may ask yourself why and when to use inheritance. Well, it is useful for code reusability. We use fields and methods of an existing class when you create a new class. Now, if you don't want other classes to inherit from a class that you wrote, you have to use the sealed keyword in front of your class. So it will be like sealed class vehicle. And then the class car cannot inherit from the class vehicle. If you will try to access a C, C-sharp, we will generate an error. This is about all with the inheritance concept in C Sharp to object-oriented programming. Of course, this is on a base level and you can go much more into detail than what I've showed you here. But this is very strong basic level of knowledge that you must understand before you go on to more complex things. I look forward to seeing you guys in the next chapter where we will talk about polymorphism. 14. Exception handling: Hello guys, and welcome back to this C Sharp tutorial. In this section, we are going to discuss exception handling in the programming language C Sharp. We are going to start by understanding what an exception is. An exception is a problem that arises during the execution of a program. A C-sharp exception is a response to an exceptional circumstance that arises while a program is running, such as an attempt to divide by 0. These exemptions provided a way to transfer control from one part of a program to another. The C Sharp exception handling is built upon for keywords. Try, catch, finally, and throw. A try-block identifies a block of code for which particular exceptions is activated. It is followed by one or more catch blocks. A problem catches an exception. We tell exception handler at the place in a program where you want to handle the problem. The catch keyword indicates the catching of an exception. The finally block is used to execute a given set of statements, whether an exception is thrown or not true. For example, if you open a file, it must be closed. Whether an exception is raised or not, the program throws an exception when a problem shows up. This is done using a throw keyword. Now talking a bit about syntax, assuming a block raises an exception, a method Kennedy's an exception using a combination of the try, it gets keywords. The try-catch block is placed around the code that might generate an exception. Code within a try catch block is referred to as protected code. And the syntax for using a try-catch looks like in the script that I showed you on the screen, as you can see, first we get the try and then we get a catch. You can list there are multiple catch statements to catch different type of exception in case you try block race is more than one exception in different situations, C-sharp exceptions are represented by classes. The exception classes in C Sharp are mainly directly and indirectly derived from the system that exception class. Some of the exceptions, this is derived from the system that exception tests are System.out application exception system, that system reception and so on. Now C-sharp provides a structured solution to the exception handling in the form of try-catch blocks. Using these blanks, the core program statements are separated from the error handling statements. This error handling blocks are implemented using the try catch. Finally, keywords. As you can see on the screen, we have pretty illustrative example where we have a division function that takes two parameters of type int. Then we declared another integrate that would be the result of the division of these two integers. And then in the try block, we say that result would be num 1 divided by num two. Now, the problem that you can expect to arise here would be that the second parameter of this function would be 0, and it cannot divide an integral number by 0. So we can put these blocking a try. And if there's an error here, we have a catch block to catch this error by throwing an exception e. So you can see that we write to the screen that the exception was caught, and we also write this exception. Finally, we are going to display the result. And in the main function we called the division function with the second argument is 0 to see what would happen if we divide these by 0. If we run this program, you can see that the result is 0, but an exception was caught. The exception system that divided by 0 attempted to divide by 0. And then the finally block is executed whatsoever with the result 0. That instantiate it right here. Because this operation right here never took place as it threw an exception. The system that divide by 0 exception. We also console.log read t, that function that reads a key from the keyboard to continue execution of the program. This is a pretty basic overview of how try-catch finally, an exception handling works in C sharp. So I look forward to getting more in-depth in the next lecture at creating user-defined exceptions. So I'll see you guys there. 15. User defined exceptions: Hello guys and welcome back to C-sharp for beginners. In this lecture, we are going to discuss the user defined exception. So as I mentioned in the last lecture, the user can create its own user-defined the exceptions in C Sharp. To use his own convenience, user-defined exception places must be converted from the exception class test the RMD requirement that you are exception class name to meet on the screen, we have an example of these user defined the exception, the script. As you can see, these mostly the warm from the last lecture. The only difference is that I created a public class. Let I be right from the except as you can see from this sign right here. And I call it result is negative, exception is direct from the exception class at the test has a constructor that has a message as its parameter. Now on our static void deficient function that we declared in the last lecture, we also inserted an if statement after the result is assign num one divided by two. And then this if statement, I suppose that for some reason you want for your division result not to be negative. So if it could be negative, you would consider that it's something that we don't want to happen. So for example, I don't know, you own a company and you want to sell something, and you want your user to check out on the positive amounts of clothes or whatever you're selling. So supposing we are mourning or web oriented environment where you would use C-Sharp. You don't want that result to be negative for that reason. I declared an if statement that checks whether the results from these, let's say oil division is smaller than 0. And if it's smaller than 0, you use the throw keyword to throw a new exception of type result is negative. With that framing, negative results found, as you can see, this result is negative. Constructor receives a parameter of type string and use that as negative results found. And then in the main function, I call division of 25 and minus 5 to trigger exactly the scenario that I discussed with you, the rest of the script remained the same as in the last lecture. And now, if we run this program, Let's see what happens. As you can see, it says Exception caught tutorial, that program plus result is negative exception. Negative results found trolling that exception. This catch block caught it as the perimeter exception e, That was this exception right here. And it printed exception caught, as you can see right here. Then a space and then the name of the exception, which was the one who gave it. And then negative result, which was the parameter of type message that if it received in the constructor, then the finally block was executed two and the result was minus five, as this was not causing an exception, it executed because there was no longer the case of division by 0. The exception was thrown over here, which meant the result was already minus 5. And the finally block executed as always. And it printed the result minus five. That's why the results change that it's not 0 as it was less than now, except the console.log and the program has finished. Thank you guys for sticking with me to the end of this exception handling tutorial on C-sharp. And for following this course, if you have any questions, you can send me a message and that will definitely help you out if you don't understand the concept or you need further explanations on any topic. Thank you, and I'll see you in future tutorials.