1 00:00:00,290 --> 00:00:04,550 Now that we've got our soccer game result data nicely parsed into a collection, 2 00:00:04,550 --> 00:00:06,160 we can perform some analysis on it. 3 00:00:07,430 --> 00:00:10,280 Since we've got data on the total number of shots and 4 00:00:10,280 --> 00:00:13,420 goals, we can calculate the conversion rate. 5 00:00:13,420 --> 00:00:16,110 To do that, we'll take the total number of goals and 6 00:00:16,110 --> 00:00:18,610 divide it by the number of shots. 7 00:00:18,610 --> 00:00:22,597 We need to add a property to store our conversion rate in the gameResult class. 8 00:00:25,270 --> 00:00:27,510 Since this number will probably have decimals, 9 00:00:27,510 --> 00:00:29,990 which data type do you think we should use? 10 00:00:29,990 --> 00:00:32,555 We don't need to be super precise, so 11 00:00:32,555 --> 00:00:36,095 let's use the default floating point type double. 12 00:00:36,095 --> 00:00:42,470 public double ConversionRate, get, set. 13 00:00:42,470 --> 00:00:45,290 Now back in our method, ReadSoccerResults. 14 00:00:45,290 --> 00:00:49,196 Back in our method ReadSoccerResults, when we load in our data, 15 00:00:49,196 --> 00:00:53,326 we can add the result of the calculation for conversion right there. 16 00:00:53,326 --> 00:00:59,875 GameResult.ConversionRate equals 17 00:00:59,875 --> 00:01:04,172 gameResult.Goals over 18 00:01:04,172 --> 00:01:09,501 gameResult.GoalAttempts. 19 00:01:09,501 --> 00:01:14,060 But since both the goal attempts and goals properties are integers, 20 00:01:14,060 --> 00:01:18,380 this calculation will return an int and not a double like we want. 21 00:01:18,380 --> 00:01:21,600 So in order to perform floating point type division, 22 00:01:21,600 --> 00:01:26,450 we'll need to cast at least one of the properties of the operation to a double. 23 00:01:26,450 --> 00:01:30,691 When the compiler sees that the first operand in the calculation is a double, 24 00:01:30,691 --> 00:01:33,965 it will implicitly convert the second operand to a double. 25 00:01:38,329 --> 00:01:43,340 One common mistake that's easy to make is to cast the entire operation, like this. 26 00:01:46,260 --> 00:01:51,180 But this will perform the integer division first, inside the parenthesis. 27 00:01:51,180 --> 00:01:52,790 And we'd lose the decimal portion of the number. 28 00:01:57,233 --> 00:02:00,980 You can also cast both of the operands like this, to be explicit. 29 00:02:03,010 --> 00:02:05,500 But, there's a better way we can do this. 30 00:02:05,500 --> 00:02:08,180 Instead of storing the value after we calculate it, 31 00:02:08,180 --> 00:02:12,450 we can put our calculation into the getter of our conversion rate property. 32 00:02:13,720 --> 00:02:19,590 We can copy this calculation, And go over to our gameResult class. 33 00:02:23,198 --> 00:02:30,590 We'll remove the setter, And put the calculation in here. 34 00:02:30,590 --> 00:02:36,098 But here, I see a typo. 35 00:02:41,431 --> 00:02:42,344 And double. 36 00:02:45,671 --> 00:02:46,674 And we need our return. 37 00:02:50,230 --> 00:02:51,073 Okay. 38 00:02:53,538 --> 00:02:56,714 And we need another curly brace, there we go. 39 00:02:59,927 --> 00:03:02,558 Back in our program class we can get rid of this calculation. 40 00:03:09,009 --> 00:03:13,490 This way, the value will only be calculated when we try to access it. 41 00:03:13,490 --> 00:03:15,060 This uses less memory. 42 00:03:15,060 --> 00:03:17,050 And since the property doesn't have a setter, 43 00:03:17,050 --> 00:03:21,040 it can't be accidentally overwritten with the wrong value. 44 00:03:21,040 --> 00:03:25,850 It's also better to do this because if the value for either goals or shots changes, 45 00:03:25,850 --> 00:03:29,370 then the conversion rate would be using the old values and would be incorrect. 46 00:03:30,570 --> 00:03:33,910 You'd have to make sure to update the conversion rate whenever you update 47 00:03:33,910 --> 00:03:35,920 the goals or shots values. 48 00:03:35,920 --> 00:03:39,070 It's a good practice to use a calculation in your properties when it's possible. 49 00:03:40,310 --> 00:03:41,818 Let's debug and take a look. 50 00:03:41,818 --> 00:03:44,051 F5. 51 00:03:51,359 --> 00:03:52,462 And there's our conversion rates. 52 00:03:56,010 --> 00:03:56,787 Great job, 53 00:03:56,787 --> 00:04:02,850 we successfully wrote a program to parse the data from our CSV file into objects. 54 00:04:02,850 --> 00:04:06,715 We used the DateTime type and learned a little more about structs. 55 00:04:06,715 --> 00:04:08,545 We also took a deep dive and 56 00:04:08,545 --> 00:04:14,415 learned about the different integral types like byte, sbyte, int, long, and short. 57 00:04:14,415 --> 00:04:16,995 Then we dove into floating point types. 58 00:04:16,995 --> 00:04:21,585 And how usually you want to use the double type unless there are other circumstances, 59 00:04:21,585 --> 00:04:25,345 like super high precision or you really need to conserve memory usage. 60 00:04:26,660 --> 00:04:30,360 All of the types we covered as we parsed were value types. 61 00:04:30,360 --> 00:04:32,720 We learned that the difference between a value type and 62 00:04:32,720 --> 00:04:35,950 a reference type is how they're stored in memory. 63 00:04:35,950 --> 00:04:39,700 We can also pass a value by reference with the out keyword 64 00:04:39,700 --> 00:04:41,750 like we used with all the TryParse methods.