[BLANK_AUDIO] Last time we talked about to use C sharp constructors to instantiate a class to create a new object. And we also talked about how we could access properties of the object that we created. This time we're going to talk about how we use methods to get at the behavior that the object provides to us. Before we start talking about the details, here is a reminder of the module learning objectives for this module. We're still working on the first one, we'll handle the second one next time. [BLANK_AUDIO] We'll immediately start with an in-lecture quiz, so you can tell me whether or not you remember how we actually access the behavior of an object. To figure out which methods we want to use, we read the documentation. So we're going to continue working with our deck class. And as we look at this documentation, we see that there's a list of. Four different methods with the description of what those methods do. So we're going to interact with three of those methods. We won't worry about the print method today, but we'll try the other three to get some practice in how we actually call a method on a particular object. We'll start with the shuffle method, so we can tell the deck to shuffle itself. So let's talk about what this documentation tells us. First of all, we know the method is public. And all the methods we're going to look at are public. So we will be accessing them from external to the deck class. The next thing is we have this indicator of what data type The method actually returns. So sometimes a method will return something to us. And we'll see that before we finish the lecture. But sometimes it doesn't. Sometimes it just, you know, the deck shuffles itself, but what would it give back to us? There's nothing to get back. And there's a special word that we use in C# to say, this method really doesn't return anything to us. And that word is, void. So the shuffle method doesn't return anything to us. Then next thing we see, I won't bother underlining it, is a method name. So the method name for shuffling the deck is shuffle. And then finally, just as for the constructor. We have parentheses that say what kind of information needs to be provided to the method. And for the shuffle method, there is no information that needs to be provided. So let's go to our environment. Now, I basically saved our project from last time and we'll build on it this time. Sometimes when you open up a visual studio project, you'll see something like this where there are no classes open and you have a big blank, blue screen, especially if I've provided some code to you, you might see it this way. The easy thing is. All along the right-hand side here, we have all the classes included in our solution. So for in console application, program.cs, we double-click it, it opens up our C# file, we zoom in. And so this is where we were working before. After printing the deck empty information, let's tell the deck to shuffle itself. [NOISE] And of course, we don't start comments with single quotes. We start them with slash slash Now. Just as here, when we wanted to find out whether a particular deck was empty we had to first provide the object, the variable, for the deck we cared about. So, we do the same exact thing with a method call. So the first thing I type is deck, and then I put dot, and then I put the method name. In this case, in this case it's shuffle, now methods, the way that we call methods, is different than the way we access properties. Because we always put parentheses just like we did with the constructor. When we called the constructor up here, we had to provide parentheses even though we didn't provide any information. Down here, same thing. Calling a method, we always have parentheses. Accessing a property. We never have parantheses, that's the rule. Okay, so I will Ctrl+F5, even though there's nothing really interesting here. So in fact, I'm going to I won't say I lied, but let's actually print the deck, both before And after the shuffle just to see that there was a shuffle. And we'll even add a blank line between the two so we can easily see where that shuffle occurred. We won't necessarily keep this code throughout the whole lesson. But we'll use it for now as sort of temporary testing code. So we'll tell the deck to print itself. And you'll notice I called this method in exactly the same way I called shuffle. I just changed the method name. And then we'll shuffle it, and then we'll tell the deck to print itself again. And in fact we better add that blank line I promised you. [SOUND] Like so. So when I Ctrl+F5, I've created the deck. I'm going to scroll up in this window, and we'll see here's the empty access. And then we see the deck is printed out in order by rank, and then by suit. We look for the blank line, there it is. And now we look at the contents of the deck from top to bottom, and we see that it's shuffled. So we have assurance that I have in fact shuffled the deck properly. Now this was temporary testing code so I'm highlighting or selecting this line. And clicking up here, that says commented out, I'm going to select these lines, and say comment them out. So that's a really useful development environment thing to be able to add code and comment it out when we don't want it anymore. Eventually, we would get rid of this code, but we'll leave it there for now. And that's it. For telling the deck to shuffle itself, our first call to a method to actually make the deck object do something. The next method we're going to look at, is cut. Because that's slightly more complicated in terms of the. The way we call the method. So let's move on to the cut and here's what's different. It's still public, it's still void, the method name is different as you'd expect. But the big difference is right here in the documentation. For the first time we're seeing something that we call that has something between those parentheses. Something that we're suppose to provide to the method. And, to this particular case it say's the location at which to cut the deck. That's what we're suppose to provide. Now, from the methods perspective this thing. This piece of information is called a parameter. From the calling side, the side where we're going to call it from, it's called an argument. The good news is, the only thing that we really care about is not the name of the parameter. But we do care that it's supposed to be an it. So when we call the cut method. We're going to provide an int as an argument. So let's actually do that. Let's put it right, well, that testing code is handy for us. [NOISE] Let's put it right here. We'll say cut the deck. [NOISE] And we're going to tell the deck to cut itself. And so we'll say cut. But when we go here, we open the parenthesis and it actually tells us in this little pop up box, it tells us, you're supposed to provide a location. And so let's cut the deck right in the middle. We'll do it at location 26. And the reason I said it's nice saved that testing code, is that I'm actually going to uncomment this again. And I'm actually going to comment the shuffle, as well. Why am I commenting the shuffle? Because the shuffle adds a, sort of randomizes the order of the cards in the deck, and I'd rather just see that the cut occurred properly. So. I meant to un-comment this, so I'll click that twice. In fact, I'll do this one again, too. So, basically we're going to print the deck in order as the deck was produced by the deck factory, if you will. And then we're going to cut the deck. We've gotten rid of, we've commented out the shuffle. And then we're going to print the deck again so that we can confirm that it actually got cut. So Ctrl+F5, and we'll scroll up to the top, just to remind ourselves that it starts with clubs and diamonds, and then goes to hearts and spades. But after the space, we see that the hearts and spades are on top. And then the clubs and diamonds are down below. So we've cut the deck properly, great. So, this debugging code that we added just to make sure or testing code if you will to make sure it's working is coming pretty handy so far. So now we've done two different methods, both of them returned void. So the first one returned nothing and we didn't have to provide anything and it just shuffled the deck. The second one it returns nothing, and we had to provide one piece of information to it. So let's look at one more example of how we call methods. The next method that we want to take a look at will be take top card, because it's fairly common for us to actually want to talk the top card from a deck, whether we're flipping it over into a pile or handing it to a player, or something like that. So, we want to take the top card. Again, it's a public method. This time though, we can see here, that it doesn't return nothing. It returns a card object. So that makes sense, right? If we're going to take the top card from the deck, we want to. Put it somewhere, or print it, or something, and so we would want to take that card. So, let's actually comment out our testing code one more time. I'll even comment out the cutting the deck so that we know which card we really expect to get. We should get the ace of clubs when we take the top card. So let's actually take the top card, take top card and print info. So this time, the method actually returns something to us, and we want to hold it in a variable. We know it returns a card, so this variable we hold it in, needs to be of, type card. I'll just call the variable card. And then we tell the deck that we want to take the top card, like so. And then we're going to print the rank and suit of the card by accessing the properties of the card, just like we accessed the property of the deck to see if it was empty. So we'll do a console right line. [NOISE] And we'll access the rank. [NOISE] And then we'll concatenate a string that says of with spaces on both side and then we'll concatenate the suit. So now when I run the code. The deck is not empty, and we get the king of spades. So I lied to you, when we print the deck, we actually print it from bottom to top, not from top to bottom. So we got the top card, which is the king of spades. And actually if you take a look at the book, it talks about why, for efficiency's sake, we want to do it that way. Okay, so I've got the king of spades, Now, a caution for you. It is in fact possible, comment out this code, it is possible, even though the take top card method returns a card object, we can still call the method without putting the result into a variable Basically what happens is, we call the method, it hands an object back to us, and conceptually anyway, we just throw it on the ground and say, I don't need that card after all. The problem is of course, that if I've done that now I can't print out information about the card. So this is useful sometimes being able to call a method that returns something without storing what it returns. But, it is not generally useful. Usually, when we call a method that's going to return something we want to store whatever it returns. And that's it for the C# calling three different kinds of methods on the deck class. One that doesn't return anything and doesn't have any parameters, one that doesn't return anything and does have a parameter, one argument from the calling side that cut Method and one that does return something but doesn't require us to provide any information. So, to recap we learned how to call various methods. And that completes our how do we handle the C# things with classes and objects. We now know how to create objects using the constructor. We know how to access the state of the objects using properties. And we know how to access the behavior of those objects by calling on their methods. Next time we'll finally get to that second module learning objective where we will in fact go through a design process for a class.