C# for Beginners - C Sharp | Aman Manazir | Skillshare

Playback Speed


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

C# for Beginners - C Sharp

teacher avatar Aman Manazir, Computer Science

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

14 Lessons (55m)
    • 1. Introduction

      1:11
    • 2. Course Overview

      1:33
    • 3. Necessary Installation

      2:32
    • 4. Hello World

      2:22
    • 5. Variables

      4:06
    • 6. Data Types

      5:11
    • 7. Strings

      4:41
    • 8. Conditionals/Comparisons

      7:53
    • 9. Methods

      3:25
    • 10. Loops

      2:49
    • 11. Arrays

      3:06
    • 12. Classes

      7:13
    • 13. Inheritance

      5:22
    • 14. Exceptions

      3:53
  • --
  • 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.

310

Students

--

Projects

About This Class

If you've ever wanted to learn computer science in a simple, understandable format, this class is for you. In this class, we discuss C#, a relatively newer programming knowledge recently developed by Microsoft. C# has dozens of new features which set it far ahead of many other programming languages, such as Java, JavaScript, Python, etc.

This class is composed of several sleek, modern, bite-sized videos which encompass key pillars of C#. Each lesson will add a new important skill to your arsenal.

After this class, you'll be able to create effective and efficient programs for a huge variety of applications; you'll be able to get started in the ever-evolving field that is computer science.

So sit back, relax, and program!

Meet Your Teacher

Teacher Profile Image

Aman Manazir

Computer Science

Teacher

My name is Aman Manazir and I am a student studying Computer Science and Mathematics at the University of Wisconsin-Madison.

I wrote my first program many years ago where I created an elementary app in Android App Inventor; since then, I've come a long way, performing University level research and building several financial platforms which have maximized efficiency. I am well-versed in C#, Java, JavaScript, and much more.

If you want an introduction to computer science, in a step-by-step understandable format, check out my class below on the fundamentals of C#.

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. Introduction: Hello. My name is a Monmouth, Nazar and I'm a university student said in computer science and mathematics. In this course, I'll teach you the fundamentals of C Sharp. You'll learn the basics of programming through step by step examples and explanations that I will provide in every video. If you have no programming experience or you're proficient in another language and you'd like to add C sharp to your arsenal, this classes for you. C Sharp is quite a newer language built by Microsoft in the last couple of decades, it was born primarily as an improvement of Java, another ubiquitous language, C Sharp, was built on the giants behind it. It retains the best features of C C plus plus and java while using an object oriented approach. This means that once you're finished with this class, you will have sufficient knowledge and understanding to quickly and effectively learn other languages such as Java and C. As these languages are quite similar, busy sharp in this class, I'll take you through the basics while introducing some advanced topics. If you want to learn the incredibly important skill that is programming and an easy to understand format, this classes for you, let's begin 2. Course Overview: hello. In this video, we'll go over what will cover in this class. If you know another programming language, most of these topics should sound familiar to you. We will start by introducing variables. Variables are part of the building blocks of any program. You may assign values to them and manipulate them later on. We will also discuss what kind of data these variables are. For example, that could be a number or sentence or many other kinds of things. Next, we'll talk about operations that you can do on these variables. You can add, subtract, multiply and divide some of them, for example. After that, we'll talk about comparisons. Comparing different variables and manipulating their values is an important part of C sharp . We will then discuss methods and their parameters. Methods are kind of like functions. You can plug a variable and and get a new variable. Back parameters are the kind of variables that you're allowed to enter into methods. Next, we'll talk about loops. Loops are simple ways to repeat coat over and over again without actually writing it out. Next, we'll talk about a raise. A razor handy waste store Lists of data will introduce the idea of classes as the fundamental building block of all object oriented programming. Whether it's Java or C plus plus or C Sharp, we'll talk about inheritance, which is a simple way to relate. Different classes together finally will introduce exceptions, which is a fancy way to describe errors and how we handle them. In the next video, we'll talk about what you actually need to download the program in c sharp. Thank you. 3. Necessary Installation: Hello. We're now going to discuss what you need to install on your computer. In order to program and C sharp, you'll need to download an I. D integrated development environment and I D is a program that allows you to write and run a programming language with ease. Technically, you can write any code in a text file and running using the consul, but that is unnecessarily difficult for beginners, so we will not be doing that. You'll need to download visual studio, either by searching, download visual studio and clicking on the Microsoft page or by going to visual studio dot Microsoft dot com slash downloads. Then, from that page, you will be able to install Visual Studio 2019 community If you're on a Windows computer or visual studio for Mac, depending on what operating system you're running on your computer. After you're finished installing visual studio, you'll need to open the application. You'll also need to designate a workspace, a workspace, any folder that you want to store your code within. For example, I chose a folder on my desk comped, but all my projects that I create within visual studio in Pick a Place that is convenient for you. You will then need to create a new project and call it whatever you want. Click on the plus side or new in visual studio, then scrolled out and click on dot net quick on council project and make sure that C. Sharp is selected. You'll then click next, give you a project in name. I'll give it a C sharp class, but you can make it whatever you want. Then pick the location for your project. When you're finished, click create. You'll then see a bunch of code written here under a tap called program dot CS dot CS. Files are the files that you'll be able to write c sharp with it. We will explain what all of this code means in a future video. Thank you. 4. Hello World: in this video, we're going to introduce your first piece of code that we're going to look at in this course I have opened here. The same file from the last video with the default code written will now go through and explain what some of this means if you don't have the same code by default, just copied down from the screen word by word, line by line. It's critical that you don't miss anything, including brackets and spacing. The important part of this code is read between these two brackets right here. Here is where we will be writing everything that we do right at the beginning of this course. All of this other stuff may look confusing, but we'll go through what everything means later on. What's important is that you focus on this inner part right here, right after this public static void made stuff we can actually hit. Enter a bunch of times to give us more room in this area. This will give us some more room to code. Notice how you can see that it already says consul dot right line in pregnancies. Hello, world cynical. Let's break this down. The consul right here is an area of your computer or an I D. E, where most of our beginner code is going. Toe output right line is kind of a function that allows you to print stuff out or write stuff to the council. So let's actually run this code To run some code, you simply have to click the play button near the top of your visual studio window. Notice how a new window has opened up on my desktop, which is the window from the terminal. Notice how hello World is printed out right there. We can actually type whatever we want between these quotes in this area. And if we click run, it'll print it out to the council. So, for example, if we type and then we click run, notice how it is printed right here in this new window to the council, this bit of code consul dot reid line allows you to print out stuff. We can actually copy it and print multiple lines out to the council. We've written here a few lines that we're gonna print onto the council from a famous movie . The Empire Strikes Back. Notice how it's printed here in the visual studio, external counsel. All of this stuff that we typed every line of code ended with some ankle. And so make sure you don't forget to put that in there. That designates to the program that the line of code is finished. Have some fun with this. Print out some fund statements, and I will join you in the next video. 5. Variables: In this video, we will introduce variables and the data types they're part of. Variables are one of the most fundamental basic parts of program. They're somewhat similar to the variables that people have learned in mathematics courses. For example, in math, we often see something like X equals three X is a variable, and three is the value associated with that variable and programming. We follow something similar. We can associate values with keywords or phrases. However, in C sharp, we must identify what type of the value is. For example, weaken type in X equals three. We're attaching the value three to the variable x notice how we have typed into right here before the X. This is declaring that X is a variable of type int or integer. Integers are positive and negative counting numbers like in mathematics, negative to negative 101 and two. Those are all integers. Integer is our first date, a time that we will discuss. Another data type is called a character, Ah, character as a single letter or digit, such as a or B or one. We can actually create a character variable and give it a value. Let's create a car C equals a notice. The differences between this statement and the above statement we have declared that C is of type character with the reserved keyword car. Just like we declare that a was of type integer We also said see equal to the letter A. We did know a character by single quotes. As you can see around a another, more complex data type is a string Ah, string is kind of like a bunch of characters group together. For example, we can create a string s equals Hello. Notice how we type the keywords string before s to denote that s is of type string If you have programmed in Java all of this is similar except string is lower case in c sharp while it is uppercase in Java. Now that we have these three variables, we can actually do some stuff with them Let's do some basic mathematical operations but some more variables and show you how they work We've created an int I equals one into j equals two and K equals I plus J because I have one Jay's to I plus j equals one plus two equals three therefore K should be called a three. We've written a consul dot right line here, which is a function we talked about in the last video. Let's check if this is correct, as we can see, a three has been printed right here. Therefore varying that condition does indeed work with imagers. We have several mathematical operations that we conduce with. These variables weaken, do addition, subtraction, multiplication and division with strings. We can actually put two strings together using the plus operator. This is a process called concatenation. That's an important word to know. As you can see here, I'm going to demonstrate that I've created a string w which is equal to world. I've also created a string A which is equal toe s plus w This will can can mate the strings and w together and print out Hello world put together with this Consul Done right line function right here. Let's give this a run, see if it works and notice how hello world is printed right here in a future video will discuss more string operations in more detail In the next video, we'll go into more detail about all the different kinds of data types that you need to know right now and their differences 6. Data Types: Hello. In this video we will discuss the different kinds of data types and what they're used for the first data type we looked at was the integer type. This data type consists of all positive and negative whole numbers. However, we only discuss the type int. But in actuality, there just a whole group of data types with the title integer. These data types all consist of integers but are simply different ranges of them. For example, we start with the type bite which goes from 0 to 255. Next comes short, which goes toe negative 32,768 to positive 32,767. Here is a table of all the C sharp indigent types and their limitations. You may notice that there is a category called BCL name. This is the official title all these data types, so technically you can type that instead of the shorthand which is on the left. However, most people use the shorthand because it is faster and easier to recognize. It makes no difference in the code. You may ask why C Sharp has all these different types. It's because some types take a more memory than others due to the fact that they can store different ranges of numbers, so you should use the type that encompasses your goal. For example, if you're writing a program, which requires a variable for a certain amount of sense, which can go over 100 otherwise you'd increment a dollar variable by one because senses only from 0 to 100 you could use a bite instead of an int or a short, because it's a smaller range and thus conserves memory. This is something that is good to know, though you don't really have to worry about it that much. Most people just stick to end when they first start learning C sharp that will work fine for anything we do in this class. We have three more dated types, which are used to store decimal type numbers like 2.5 or 1.5. Anything that an integer type can't store these air, called float and double. These are different limitations as well. There's one more call decimal, which is shown in this table on screen, this one as a smaller age but is much more precise, as shown by the significant digit category. You don't really need to worry about this, for this class will just mainly use double. The last two data types are called Character and Boolean. These two types aren't digits, the 1st 1 to use for characters or different possible letters, numbers or signs such as A B, C three or a dollar sign. Characters air any letter or number, but they can only be on digit or letter or signs. No more Bull Ian's Can Onley either be the value, true or false? They're useful for if all statements, things that we will get to later every type discussed so far in this video are part of a category of data types called pre defined types. That's an important word to know you can actually create your own data types later on. But those data types are all built up from these pre defined funds. With these pre defined types, we have something called operators. Operators are things that before operations on different variables of a specific data type , such as plus or minus or times or divide. For the most part, these works similar to how they are mathematics, however, something maybe only to know now is that if you divide two integers using the divide sign, it performed something called integer division. This is important because if you defied two integers and that division doesn't return a whole number, meaning you have a fraction it will floor the result. This means that say, if I divide five divided by two, I'll get to not 2.5 because 2.5 isn't an integer. Here's an example of this. Notice how I defined an integer L, which is equal toe I divided by J eyes one in Jay's to and maybe l should be 1/2 but as we can see, it is not so. Notice how zero is printed. This is because C. Sharp has floored our value, moving it from 0.5 to 0. It kind of just chops off the decimal points, so if it was 1.5, it would round down toe 12.5 to 3.534 point 254 And so on. There's some other rules with operators on pre defined types like character, but those aren't really that important for beginner programmers to worry about. There's a term called a literal which is important to know. Ah, literal value is a representation of a constant value in the source code. This means that every time you write a three or 4.5 or in a, it's a literal value. This will become more clear in the future when we discussed strings and string methods in the next video. 7. Strings: in this video, we're going to break down strings and the methods that you can do with them. Strings are a data type that are composed of several characters in a line. Strings are denoted with double quotes, like so to create a string simply type string for name equals doubles, whatever you want, this bar name to be equal to will be put within these double quotes. Strings are slightly different than the pre defined types we talked about in the last video . They are called reference times. This means that when you create a string and give it a name, that name points to the string object That name stores a reference address to that object. Here is a diagram that shows how this works. When we create a string, we write down its name and then it has a reference shown by this arrow to its value over there. If we created other string, it looks like this with its name and value. However, if we create 1/3 string with the same value as one of the other strings, it doesn't just point at that one instead creates a whole new value points to that. It has a unique reference. Now suppose we sat string one you will to spring to. What happens is that you were changing the reference of string one to the reference of string to strength one now points of the same value as string to a good way to think about this is picturing the variable name as an envelope with an address on it. Think of the value of the string as a house. If you set one envelopes name equal to another envelope, you would just change. The address is written on it, not the actual houses. One detail about strings Are that there immutable? This means that wants you to finest friend. You cannot change the actual value. You can't change the house. You can only reassign the reference the address to another string. With that, let's discuss some string methods. String dot com cat string One string to is a method or function that will allow you to contaminate two strings together. Just like this of our three should be far name and bar to put together. So hello world all smashed together big and show it like this As we can see Hello World is printed right here to upper and two lower are two more methods that take a spring and return the lower case or uppercase versions of that. If we write var to to upper and print out far too, what do you think will happen? Let's try it. Notice how world here was printed, not capital world. Why is this? This is because strings are immutable. You can't just right far too to upper and expected to change two over returns the upper case version of our two. So if we do this and we print out of our four instead of our two now we can see that we get the capital world right there. You can actually change the value of a screen. You can simply reassign it to another one. So in this case, we had to reassign the over case version of our two to a new string and then print that out . Str one dot trim is a string method that gets rid of any white space on the ends. Such a spaces or new lines just like this. If we print out string one as it is, we will get hello with a bunch of spaces around it. If we don't want this, we can print out this instead. Str one dot friend This method will return Hello With all of the white space spaces of new lines on the outside removed. Let's show you how this works. And as you can see, we have Hello right here within no spacings. There are many more string methods that you can look up all that, but these are the main ones. 8. Conditionals/Comparisons: and C sharp. We will often want to compare different variables to see how they relate to each other. There are several operations that allow us to do just that. Let's create and into X equals five and in. Why people For now we can compare these two and C sharp will tell us whether they're equal or not. This equals equals. Operator will return true if X is equal tow line and will return falls. If they're different, let's test us and see if it works. Notice how ah, false was printed. This is because X is not equal to why in this case. Conversely, if we change y to five and try it out again, we should get true and we do right here. This works with strings as well. If we create to strengthen the same value and tested their equal to each other, we get true. Notice how we get true here if you're coming from Java. This may seem peculiar and odd because this works differently with strings and job. However, in C sharp checks, the values, not the addresses person. Another two operators that compared variables to each other are the greater than and less than operators, just like in mathematics. These work how you might expect. Let's write this out and show you how it works. If we have into X equals five and into Eichel's Oregon Weaken test, if X is greater than why or less than let's see what happens with me, notice how true is pregnant right here. This is because in our case, X is indeed greater than why it's probably less than operator See what happens and, as expected, falls is printed. This is because X is not less than why in our piece, the opposite of equals equals is not equals to this operator right here. Exclamation point equal sign is testing whether X and Y are not able to tell, so if they're not equal to each other, it will return true. Let's see what happens when we try to find before exactly notice how true is returned. Why? Because we tested whether they were not able to each other, and in our case there weren't so we got to back. Now let's put this stuff to work. We will now introduce the basic idea of condition. ALS conditional are expressions that will evaluate based on comparisons. The basic conditional is the if statement it works like this. We can write something like this. If X is greater than why, then whatever is within these brackets is gonna happen. The code test this expression right here. If a truce returned this in, the brackets will operate. Let's test this out So this will only print out if X is greater than what? As you might expect, X is greater than what. So we should get a Hello, Let's test this out. Notice how hello is printed. Perfect. Basically the stuff in the parentheses of the if must have a boolean expression meaning that you can't shove anything in there. It has to be a true or a false because our comparisons returned. True or false, it works in there. If we put in just like a five, for example, we're going to get an error. As you can see right there, This is because five is not true or false or boolean expression. We need something that the code can actually read. We can put true in there and you know this how it works out and if we click Run. Ah, hello, Piers. This is because, true or false, a readable by the code, we will now add the else conditional. This conditional expression will only operate if this first conditional expression does not . So let's make it something that we know is false. X is definitely not less than why, because excess five y sport. So this for sure isn't going to run. So whatever's in here should Ra let's put some stuff in there, check it out. That's wrong. This notice how we didn't get a hello will be gone this work instead, This is because over here X is not less than what. So this if doesn't operate and instead that else does. That else can only operate. If the if doesn't we also have else, if else if our conditional, which test a bunch of different conditions, That's easy to see. When you Right now, let's try this. So what we've put here is if X is less than why we're going to get a hello, probably not because X is greater than one. If X is equal to why will get of this didn't work. And finally, if X is greater than why will get a let's go and I want. Case X is greater than wise. So hopefully this works we get, Let's go. And indeed we do get Let's go only one of these else if statements can actually run, for example, if we put the else if X is greater than why ahead off this or a better table would be if we put in l stiff axes, not ableto and right in these something like notice how both of these statements are actually true. X is not equal to y and X is greater than why. But only this one is going to run, because as soon as the else is executed, this entire thing is short circuited. As you can see here, let's try this exactly. No, this out. Let's go spread it here and the collect to undermine Pascoe is not, as you can see right here. Another, more complicated, conditional is called a swift statement. The switch statement is another way to test the bunch of cases with a more streamlined approach. Let's try this out so we frightened out a bunch of the code here, and I'll go through with this means. So the swift statement test what's ever in these parentheses and a test whether it's equal to whatever you put after these different cases. So case one meat is gonna test whether case which this integers equal to one case to is to and default means that whatever's here is going to run no matter what. So if case one is true, then this is going to run and break means that this is all going to be sidestepped. Kate of case to is true in case one is false. That this will print out and break means that the total if none of these are true than the default statement will run and default case will get printed and finally break means that switch statement. Let's see what happens when you do this. Notice how case one is printed right here. This is because case, which was indeed equal toe one. So our case one case here was the one that execute These are all the conditions will talk about in this video. Have some fun with this right up some code and we'll see you in the next video 9. Methods: in this video, we're going to talk about methods and how to create them. Methods are the diverse functions of programming. The basic idea is that you can input something and get something new out there. A syriza, computations or many different operations. Let's think of a basic mathematical function. There could be a function that if you input to numbers that spits back out to some of them . So if we put in three and five, we get eight. Let's program this. The first thing you put into a method is the access modifier. This is a key word that simply tells you whether external classes can access its method. It's very important later on, but right now you don't really have to worry about it. Just put down public. The next keyword determines whether the method is static or not. You don't have to worry about this one either. Just put down static. The next modifier is very important. It defines what data type the method returns, so if it's returning and you put down into or a string you put down straight in our case, we're putting damage. If your method doesn't return any specific value at all. Then you put down the keyword void v o i. D, which means the lack of a return. Let's go with it. So right now we have public static. It now comes the method name. Let's call this method some numbers. This is describing what our method does. It's taking the sum of two numbers. Let the names and see sharper, usually camel cased, meaning that the first word is lower case and the rest are uppercase in the name. Notice how some was lower case and number in his upper case within the parentheses that follow you to find the input values. For example, in our case we're in putting into a into B. These are present the two numbers that we're taking the summer off. These are called the Method Parameters. Now comes the part where we actually write the method we put down to curly braces to designate the body of the method. Notice how we have an error. We'll take care of this in a second. Now let's write this code so we can create NC, which is equal to a loss. Simple sees the sum of the two input parameters. As you can see here? No, we still have an heir. This is because we told a code that we're going to return. And as we wrote right here, but nowhere in our code do we actually say what we're returning or when we do So? So, to fix this, all we need to put down his return to see that way. The code. No, we're returning seat. There we go. Our method is written. Now we can actually call this method and show you how it works. Let's do this. As you can see here, I'm simply out putting to the consul some numbers with three and five and put it just like our example above. Let's see what this does. Notice how eight over here is input it. There we go. That means that our method works in this class will initially focus on writing methods. Within the same file is our main class. You may notice that this main thing over here, the thing you've been writing code in since the beginning kind of looks like a method. That's because it is. It has all the same keyword placements as we discussed before. Public static void made. We'll discuss why it's public and static and what this string ARDS means in a later video. This is a method, and you can do a lot with it as well discuss in the future. 10. Loops: In this video, we will discuss the loops. Loops are the tools that programmers used to repeat code over and over again without actually writing it out a bunch of times. For example, if you wanted to print out the numbers from 1 to 100 would you have to ride out? Ah, 100 lines of code of print statements you could. What about 1000 10,000? Pretty soon you're gonna want a better way. Loops are our solution, and we will discuss a few ways to create them. The first loop that will look at is called the Wild Lyle. Groups are based on the idea that the code with and then we'll repeat while a certain condition is trip. For example, let's think of a solution as long as an integer X is less than or equal to 100 or Kotal print out X and then add 12 x each time. This will theoretically print out numbers from 1 to 100. Let's write this so we start with while and we put our condition in the parentheses. But first, let's create our X, so as long as acts is less than or equal to 100. Whatever we put in these curly braces is going to run. Let's write down console dog Bright Line s this is gonna print out ex every time this week brogues. Then every time it runs will add one toe X through the X plus plus operation. This basically this adds one toe acts. Let's run this and see what happens As you can see the numbers between 1 to 100 or, in this case, 0 to 100 because X started zero. But anyway, numbers from 0 to 100 are printed out on all new lines and we didn't have to write 100 different lines. See how simple and easy that was. The second kind of loop we're gonna try out is called a four loop. This is mainly used for situations that we have a set number of reputations. Let's print out the same thing as before, using one we first, right, four and then we define a counter sorts. This counter is going to go from a certain number two another. Let's define it into I is equal to one. Then we put the condition upon when this for Lupul run, I is less than or equal to 100 finally will put I plus plus. Then whatever we want to run when the loop is running will be put inside these curly braces . This actually looks really similar to the wild loop, right? That's because, technically, you can do everything with one loop, as you can do with the other and certain situations. However, it's easier to use one of them now within the brackets. That's right. A similar thing. Consul Doug. Right line I. And there we go. We get the same result. Let's try this out. Notice how we get our numbers from 1 to 100 just like before. Perfect. These are just two kinds of loops. If you continue with programming, you learned about some more kinds of loops. But this is all we'll look at in this course. 11. Arrays: In this video, you will discuss a raise one of the best structures to store large amounts of data the basis behind a raise that their container to store long lists of data of a common type. For example, suppose we need to store pet names from a pet store. We could have an array of strings that stores each pet name. Here is a visual that demonstrates an array. Each box has an item in it, in this case, a pet name. The boxes are also numbered. Something peculiar about them is that they index from zero, meaning that the first box has a number of zero and so on. We have the ability to access a specific box based on its number. Some other things we could do with an array are get its length set certain elements or boxes, different values and get the value at any index. Now let's actually declaring a raid. This is how we start declaring a raid. This is how these are declaring the rain. You write the data type and then two brackets just like this to signify that we are creating an array. Then you put down the arraign name and set it equal to something. Now we have some options. If we already know what we want in the array, we can use curly braces like this and put some stuff in here like so 12 and three. However, if we want to create an empty array, you simply said in equal to this new end six with the data type written here and how many spots you want in the array within the brackets. When you don't specify what's inside the array like this, the default value for all pre defined types is zero. If you have a reference type, it's going to be sent to know, which means no reference. We can do a lot of stuff with the rays. So let's changes, array and stop one of its elements to another value. We can access an index like this array test array by putting the index number within these brackets right here. This allows you to access the element at that position. But remember a raise index from zero, meaning that the first element is at zero seconds at 1/3 at two and forth is at three. So here were actually setting the fourth element off test arrayed to be ableto three. Let's test out of this worked. Let's run this notice how three down here was printed in the terminal. Also, there was an update while I was making this class to visual studio. And now by default. If you have visual studio for Mac, the consul or terminal will be printed down here by the fall. To get the arrays length, we simply type its name and then dot length with a capital l like. So let's test this and see if it works. Notice how six was written down blow. That was because we set the length of six when we initialize the array right here above. That's all we'll talk about in this video on a raise. In the next video, we'll finally get into classes and describe how they build up C sharp 12. Classes: in this video, we will talk about classes. Class is truly build up all of programming. The primary use of classes is organization, but we will expand from there and break down exactly what they are. So let's focus on an example. Suppose we look at a school in a school. There are a whole host of different things, like students, desks, teachers, etcetera. Each different thing in the school has a different set of properties. Students learn stuff. Teachers teach and desks are for writing. What if we could create a set of rules? A set of guidelines for students, a framework for which we could input, identify IRS induced up with, for example, what have figured create, say a student entity and add a name. Student I D GP, etcetera. This is the power of classes. They allow you to create a general framework for a type of object that could be specified in a few key details. Let's try to make this first. We always put down public class class name in our case class name is the name of the class , but you can choose anything you want. In this example, we're gonna put down student because student is the example classes were going to make. Now, in the next video, we'll discuss what public means and exactly why we put that down between these brackets. You'll write all your code to detail exactly what a student can do. We can set up some variables or fields that are accessible and could be changed for a student. So what are some properties that every student in the school would have that people would need to retreat? Well, we have name, student I D and GPS, so let's create those things we can write private string name, private into student I. D. And private Double GPS. So now our example. Student has a name, a student I D and G. P. A. We'll talk about why their private in the next video. Now we need to set up what actually sets the default values for these fields. When you create a new student, how do you set the base values for all of the's? How do you set what values thes three variables will have when a new students created the thing will use to do this is called a constructor. It's kind of like a method but slightly different. So I've written our constructor right here. I'm going to go through exactly what this means. So we first right Public student, string name and student I d double G p a and then some curly braces with some stuff inside . This kind of looks like a method, but it works slightly differently. Basically, when the user creates a new student, they input the name that they want as default. The student i d that they want for default and the g p A that they want to set initially. Then our code goes and sets all three of those values. Basically, when you put down the this keyword, as you can see right here, you're targeting the class field. Notice how name up here is highlighted. Not the name Over here. This name is targeted. When we just write name down. As you can see, they're both highlighted. What this is doing is this is setting this name equal to this one. So we're basically setting the class field name equal to the method perimeter. The way that works is that when the user inputs what name they want, it changes the name for the entire class. It doesn't just stay in here. Similarly, our student ideas air changed here and our GP a set here. You'll see exactly how this works in a bit. Now we need to write some methods to actually retrieve all of these fields, along with changing them if need be. Something that changes the fuel is called, um you Tater and something that gets the value of a fueled It's called on access. Er, let's do this. As you can see, we've written some new code all here. If you look closely, all of these either get a class field or set a class field with the example down here. So notice how we have a method called get name to public method will explain that in the next video it returns a string because it returns the name and the user can call it by calling get name Basically like before. I explained how when you put this in front of a variable name, it targets this name appear notice that these two are highlighted. That means that the same thing all this method does is return the class field name. As you can see up here and over here. It's similar with desk agent I. D. All it does is it returns a student i d that which is the class field up here. Same thing with G p. A. Which is a double student ideas and pretty basic stuff. Now, down here, this one is slightly different. It's not too complicated. All it does is have an input for G p A as a parameter and it looks almost identical to the constructor. Basically, you're setting the G p A, which is a class field equal to the method perimeter. As you can see, visual studio actually highlights what we click on if they're the same thing, which makes it a lot easier to see and understand. Now let's actually create a student and see what we can do with it. Alright, so I've written some code in the main method of our main class. Let's see what this does. So, over here I've actually created a new instance of the student class. The way you do this is similar to a raise you put down student, which is the name of the class. That name is basically assigning this reference student one to be a reference of type student events of that equal to new. What new does is two things one and allocates space and memory in two and returns an address to the new object in creating. You're creating a new student object with these three inputs. Notice how we have the name Dwight. We have the student i d. 000001 and the G p a four point. Oh, these three values are going to be placed in these three spots. And because of that are three class field, as you can see right here are going to be changed to what we input. It's really like a method. All it is is these three parameters are going to be shoved in the story spots by this stuff right here. Take a second and pause a video if you need to think about it a little bit more. Finally we start to do some stuff with this code. So we first right, consul dot Right line student, one Dugit name. We're calling the get name method on student one. Our new student and we just created this theoretically should return Dwight because we set the name to Dwight over here. Let's see if that works and exactly notice how Dwight is printed perfectly right there. We then use the set G p A method on student one setting our deviated 3.5. And then we do a similar thing as up here, and we print out the G p a. The new G p A that we just set using the get G p a method. Let's see if this works and perfect notice how 3.5 is printed right here exactly as we expected. Classes are powerful things. They offer a huge amount of versatility and the next video we'll discuss outclasses, relate to each other and inheritance. Have some fun guys, and I'll see you in the next one. 13. Inheritance: inheritance is a hugely powerful tool in C sharp. It allows us to create smaller and more niche classes, which are general variants of bigger things. Let's talk about an example. We could have a class called furniture, so let's create this. So we have a class called furniture right here. If you're still confused on what all of this stuff means, meaning, like, why do we have different fields here? What does this do? What do these do? We watch the last video or look up some more stuff online. It should be pretty clear what to get the hang of it. So over here we have three fields, one for the brand, which is the string by from my Kia or different brands. For furniture. We have an integer for the weight in kilograms of pounds. Doesn't really matter. For example, any of a string for the color like blue rad brown. Whatever color it is, we have a constructor right here, which is going to set the brand weight and color to what the user wants. Then we have about three methods here just to get the brand just to get the weight and just to get the color. Pretty simple stuff. We all discussed how this works in the last video. What if we wanted to create a chair class? Well, a chair is a piece of furniture. So do we now need to set up all of the same stuff and put all of that into the chair class and then add on to it. This is the power of inheritance. We don't actually have to do that. All they can do is use one keyword and get all of this in our chair class and then add on to it. It's extremely powerful. This is where inheritance comes into play. I'm gonna show you sparks. So let's create a chair class. As long as we create our chair class like this and write a colon with furniture, we can say that chair inherits furniture. And because of that, now, when I feel in this chair class, all we have to do set up new methods and fields that aren't in furniture. Okay, so we've added some stuff here and it looks really complicated right now, but I'll explain it and it will feel simple after that. So let's do this. We have a private and legs here. This is the only new field I'm going to add because all furniture doesn't have to have legs like all chairs do. So I've added a certain field four chair that isn't in furniture. I'll explain how chair contains all of this stuff later, we now have our constructor for chaired. It has a brand weight, color and legs because the user would still have to input what brand weight color that the chair is. After all, it's still a piece of furniture, so the user still needs to tell the code what each of those items are. However, instead of using all of this stuff here, all we do is put another colon like this, and then we put base and those three values this base keyword basically calls the constructor from up above and inputs these three things that we have as our parameters. Notice how they match up then, in these curly braces, right here we have this dot legs equals legs con. The same is up above this targets that will legs targets that likes pretty simple stuff, not too difficult to understand. It may seem hard right now, but once you get the hang of it. It will be easy. Now we can create a new method for chair to get the legs. And then I'll show you how Chair is able to use all of the stuff off above through inheritance. All right, so we have a get legs method right here. And now let's put this to the test. Let's see if this actually all works. Okay, so we've created a new furniture object. We've called it furniture one. It has the brand of Kia, the weight of 35 the color of red. We've then printed the brand of furniture one using the get brand method, as you can see down below and up here to the council. Let's see if this works perfect. Like es printed right here. Now it's getting many stuff and see if we can use inheritance to create a chair. Okay, so we've created new chair, As you can see right here we and put it the brand is a key of the weight is 20 the color is red and the number of legs as for as per dictated by dis constructor over here reminded video if you want a refresher on this is. We've also put a console that right line, and we're going to print out the color of the chair using the GATT color method. As you can see right here now, the power of inheritance is going to be highlighted when we do this, because we never actually defined a get color method in this chair class. Look around. You don't see any get color method. You only see again legs method. As you can see right here, Chair gets the get color method from its parent class furniture, and that's the power of inheritance. We didn't have to repeat it because chair as a piece of furniture. And if you wanted to create something that was a certain type of chair, you wouldn't have to repeat any of this stuff, either. It creates, ah, hierarchical nature. As you can see with chair being a part of furniture and something else could be a piece of a chair and so on. Let's test this perfect. I Kia and Red are hunted down below, as red is the color of this chair. Now let's see if the legs method works, and if the legs are printed, perfect four is right here, and that's proof that all of our code absolutely works. Inheritance is super powerful when you're creating a ton of different classes and I will see you in our next video, our final class video. 14. Exceptions: and C. Sharp exceptions are extremely important. They enable you to pad your coat to protect against errors. An exception is, at its essence, an unexpected event. When something happens, that's not supposed to happen, an exception is thrown. They're kind of like errors. So, for example, if we try to find the index of an array that is greater than its length, we would get an exception that tells us what mistake we made as soon as it's in steak occurs. An exception is quote unquote thrown by the code. So how do we actually get rid of exceptions? Well, the first thing to do is prevent them from occurring. So don't do the wrong things that cause them. For example, don't try to find an index of an array that is beyond its length. Sometimes, however, we have to absolutely deal with exceptions. So we do something called a try. Catch a try Catch is a mechanism that try some code and catches an exception if it is thrown by the code. That way, it doesn't totally break the code, but something logical happens if the exception does occur. The way we do it is like this, so we write tried with two curly braces right here. Then catch an exception, E. And we put some stuff in here, so the code is going to try some code in here. If an exception is thrown and there are example, it will be thrown, the code will catch it and label it as e. Then we can do something with that exception in this curly braces instead of the code completely stopping. Let's try this. Okay, so right now we've created a new array, which is of length three, and we're gonna try to print out the fifth element using the consulate. Right line already. You should have an alarm going off of your mind because there is no fifth element. So theoretically, we should get an exception. But we'll see what happens and exactly notice how nothing happens and the code doesn't break. Why is this? Because an exception was indeed created, but it was caught by the code, as you can see right here. And nothing happened because we have nothing in these braces. So let's put some stuff in these braces and see what happens. Okay, so we've written Consul, that right line you messed up So technically, this should print. Let's try this. And exactly You messed up was printed perfectly right here. So the point of this is to print out or do something with the code, Kind of like a backup mechanism and set up our code. Totally breaking. We have a safeguard a plan and action so that we control the situation, not the code. I'm gonna show you what happens when we don't have a try, catch in place and do the same thing. So right now, we've removed all of our try catch mechanisms, and we just have a code right here. Let's see what happens. And as you can see, we have an error here. System not in next. Out of range. Exception has been through the code completely broke. Now, we don't want that to happen. We want to choose what's gonna happen, not the code to do that, use a try, catch and put down exactly what I showed you. Exceptions are very useful and important, and this is the basics of them. So if you made it this far, I'd like to thank you so much for being a student in my C sharp course. It really means a lot, and I'm so thankful and grateful for you taking the time toe study and learn from I C. Sharp course. If you want a branch out from here, there's a couple offense that you could do. You could either learn more, see sharp through a textbook or another online course. They're a bunch of those. Or maybe you could branch out and learn a different language. I would recommend Java or python. I actually started on job A so I kind of bias towards that. So actually I'd recommend going for Java. But you can do whatever you want. The world is your oyster. I'd like to say thank you again and goodbye.