1 00:00:00,770 --> 00:00:01,960 How did you do? 2 00:00:01,960 --> 00:00:03,679 Let's take look at my solution. 3 00:00:03,679 --> 00:00:07,710 In album class, I added second method named loan. 4 00:00:10,518 --> 00:00:16,603 Public void Loan And just 5 00:00:16,603 --> 00:00:22,270 like before since this method won't return a value, I used void for the return type. 6 00:00:22,270 --> 00:00:27,300 Actually, when overloading a method, the return types have to match. 7 00:00:27,300 --> 00:00:31,670 If they don't match, the C# compiler will generate an error. 8 00:00:31,670 --> 00:00:34,500 Since this version of the method will be used to loan out an item 9 00:00:34,500 --> 00:00:40,110 without supplying the loanee's name, we don't need to define any parameters. 10 00:00:40,110 --> 00:00:43,600 For the method implementation we could just repeat the code 11 00:00:43,600 --> 00:00:45,350 to set the online field to true. 12 00:00:48,910 --> 00:00:54,300 Or we can call the new loan method from the old load method. 13 00:00:54,300 --> 00:00:58,675 Notice though that now we're setting the on loan field to true in two 14 00:00:58,675 --> 00:01:01,660 different places here and here. 15 00:01:01,660 --> 00:01:06,870 Inside of this method overload, instead of setting on loan field to true, 16 00:01:06,870 --> 00:01:08,900 let's just call the other method. 17 00:01:11,530 --> 00:01:15,107 Doing it this way helps to keep our code from containing any 18 00:01:15,107 --> 00:01:17,560 unnecessary duplication. 19 00:01:17,560 --> 00:01:21,680 The approach of calling a method overload from within a method overload 20 00:01:21,680 --> 00:01:23,920 is something that's commonly done. 21 00:01:23,920 --> 00:01:27,240 Next, I updated the GetDisplayText method to account for 22 00:01:27,240 --> 00:01:29,590 with the Loanee field doesn't have a value. 23 00:01:34,342 --> 00:01:40,500 So, if Loanee does not equal null and 24 00:01:40,500 --> 00:01:46,666 Loanee does not equal empty string. 25 00:01:50,180 --> 00:01:54,751 Adding the second check to make sure that the Loanee field isn’t set to an empty 26 00:01:54,751 --> 00:01:57,540 string makes our code more resilient. 27 00:01:57,540 --> 00:02:02,980 This is a very common thing to do to check to see if a string is not null and 28 00:02:02,980 --> 00:02:03,980 not empty. 29 00:02:03,980 --> 00:02:07,650 This is so common, that the .net framework string data type 30 00:02:07,650 --> 00:02:10,580 includes a special method that we can use for this purpose. 31 00:02:14,175 --> 00:02:17,831 String is null or empty. 32 00:02:19,050 --> 00:02:22,090 Then you pass in the string that you want to check. 33 00:02:22,090 --> 00:02:24,270 In this case, the Loanee field. 34 00:02:24,270 --> 00:02:26,660 Since this method checks that the string is null or 35 00:02:26,660 --> 00:02:31,170 empty, we need to add the not or the logical negation operator 36 00:02:31,170 --> 00:02:34,110 before the method call in order to negate the return value. 37 00:02:36,530 --> 00:02:42,620 So if the method returns false, meaning that the string isn't null or empty, 38 00:02:42,620 --> 00:02:48,310 the not operator will flip that to true and satisfy our conditional statement. 39 00:02:48,310 --> 00:02:50,380 So if we have a loanee field value, 40 00:02:50,380 --> 00:02:52,880 then I append the text like we previously were doing. 41 00:02:54,945 --> 00:03:00,813 And if we don't have a Loanee field value, 42 00:03:00,813 --> 00:03:08,485 we can use this else block to append the following text. 43 00:03:12,195 --> 00:03:17,110 Currently on loan. 44 00:03:17,110 --> 00:03:18,670 And that's the best we can do. 45 00:03:18,670 --> 00:03:20,425 We simply don't know the Loanee's name. 46 00:03:20,425 --> 00:03:23,338 In the program.csfile main method, 47 00:03:23,338 --> 00:03:29,444 I added a call to the loan method overload and another call to the return method. 48 00:03:31,431 --> 00:03:34,344 Album2.Loan, this time, 49 00:03:34,344 --> 00:03:39,593 without passing any argument, and album2 Return. 50 00:03:41,960 --> 00:03:46,070 I also added two additional console writeline method calls. 51 00:03:46,070 --> 00:03:50,940 Here, let's write album2's information to the console, and down here. 52 00:03:54,040 --> 00:03:56,830 And lastly, I compiled and ran my program. 53 00:04:04,510 --> 00:04:07,340 And here's the expected output. 54 00:04:07,340 --> 00:04:11,450 Here's when an item is out on loan and we know the loanee name. 55 00:04:11,450 --> 00:04:15,790 And here's when an item is out on loan and we don't know the loanee's name. 56 00:04:15,790 --> 00:04:18,260 Excellent job completing this practice session. 57 00:04:18,260 --> 00:04:20,850 Be sure to check out the next session in the series 58 00:04:20,850 --> 00:04:25,030 after you've completed the third stage in the C# objects course. 59 00:04:25,030 --> 00:04:27,510 Thanks for practicing with me and we'll see you next time.