1 00:00:00,303 --> 00:00:02,230 Here is our Wait method from earlier. 2 00:00:02,230 --> 00:00:05,536 It would be nice to be able to specify how long it should pause for. 3 00:00:07,725 --> 00:00:09,955 We could do that by passing in an argument. 4 00:00:09,955 --> 00:00:14,004 For example, we can pass at the number of milliseconds to wait for. 5 00:00:14,004 --> 00:00:18,365 3,000 milliseconds will cause it to wait for 3 seconds. 6 00:00:18,365 --> 00:00:20,930 But if we save this code and try to run it, 7 00:00:24,224 --> 00:00:29,176 We get a compiler error, no overload for method Wait takes 1 arguments. 8 00:00:29,176 --> 00:00:32,470 In other words, a call to wait can accept an argument. 9 00:00:32,470 --> 00:00:36,020 We can give it to accept one using method parameters. 10 00:00:36,020 --> 00:00:40,463 Here's a program that declares an Add method that accepts two parameters and 11 00:00:40,463 --> 00:00:44,238 then another subtract method that also accepts two parameters. 12 00:00:44,238 --> 00:00:48,132 A parameter is a special variable that you declare at the start of a method. 13 00:00:48,132 --> 00:00:49,981 It's just like declaring a variable. 14 00:00:49,981 --> 00:00:53,044 You specify a type and a name for the parameter. 15 00:00:53,044 --> 00:00:57,492 You can specify multiple parameters by separating them with commas. 16 00:00:57,492 --> 00:01:01,992 Within the method body, you can access the parameter just like you would a variable. 17 00:01:01,992 --> 00:01:05,361 In the Add method, we print the value with the first parameter and 18 00:01:05,361 --> 00:01:07,758 then print the value of the second parameter. 19 00:01:07,758 --> 00:01:12,040 Then we print the result of adding the first and second parameter together. 20 00:01:12,040 --> 00:01:13,677 When a method takes parameters, 21 00:01:13,677 --> 00:01:16,786 you need to provide argument values when calling that method. 22 00:01:16,786 --> 00:01:21,421 C# sets each parameter value with the value in the argument. 23 00:01:23,593 --> 00:01:28,101 So this first argument to Add is going to be the value that the first parameter 24 00:01:28,101 --> 00:01:28,882 gets set to. 25 00:01:31,770 --> 00:01:36,021 The second argument in the method call is going to be the value that 26 00:01:36,021 --> 00:01:38,272 the second parameter gets set to. 27 00:01:38,272 --> 00:01:45,790 Let's save this and try running it, with dotnet run. 28 00:01:45,790 --> 00:01:49,365 And you can see that it prints the value of the first parameter, then the value 29 00:01:49,365 --> 00:01:52,730 of the second parameter, and then the value of adding the two together. 30 00:01:58,402 --> 00:02:01,358 Let's try adding another column with different arguments. 31 00:02:01,358 --> 00:02:04,710 So I'll call Add and pass the first argument of 10.5 and 32 00:02:04,710 --> 00:02:07,940 the second argument of 7.2, let's try saving that. 33 00:02:10,535 --> 00:02:12,226 And running it. 34 00:02:14,872 --> 00:02:18,445 And there we are, and our first parameter is set to 10.5. 35 00:02:18,445 --> 00:02:22,510 Our second parameter to 7.2 and here's the result of adding the two together. 36 00:02:26,490 --> 00:02:30,567 Let's try calling this subtract method with a first argument of 9 and 37 00:02:30,567 --> 00:02:32,168 the second argument of 3. 38 00:02:32,168 --> 00:02:33,624 Let's save this and try running it. 39 00:02:39,708 --> 00:02:44,604 And here we are at the bottom, our first parameter is set to 9, our second to 3, 40 00:02:44,604 --> 00:02:47,632 and here's the result of subtracting 3 from 9. 41 00:02:47,632 --> 00:02:51,089 One last call, let's call Subtract again with different arguments. 42 00:02:57,513 --> 00:03:01,130 21.3 and 7.1 save this. 43 00:03:02,673 --> 00:03:04,049 Run it? 44 00:03:04,049 --> 00:03:07,987 And there's the results of calling Subtract with different arguments. 45 00:03:09,846 --> 00:03:12,496 Let's take what we've learned and fix our Wait method. 46 00:03:12,496 --> 00:03:16,717 We want to be able to pass an argument to it with the number of milliseconds that it 47 00:03:16,717 --> 00:03:17,663 should wait for. 48 00:03:17,663 --> 00:03:20,480 But right now we're getting an error saying no overload for 49 00:03:20,480 --> 00:03:22,124 method Wait takes one arguments. 50 00:03:22,124 --> 00:03:25,772 That's because we haven't set any parameters up in the definition for 51 00:03:25,772 --> 00:03:26,693 the Wait method. 52 00:03:26,693 --> 00:03:29,925 Let's go ahead and add one now and see if that fixes it. 53 00:03:29,925 --> 00:03:35,163 So I'll add an int parameter because this is going to accept an integer and 54 00:03:35,163 --> 00:03:36,777 we'll name it delay. 55 00:03:38,449 --> 00:03:42,752 I don't need to make any other changes to the method except to take this hard coded 56 00:03:42,752 --> 00:03:47,072 3000 millisecond value and replace it with the name of the delay parameter. 57 00:03:47,072 --> 00:03:50,897 Let me save this and we'll try running it. 58 00:03:53,201 --> 00:03:56,677 You can see it says waiting, it waits three seconds and then it prints done. 59 00:04:01,174 --> 00:04:04,836 Let's try adding a call to wait with a different argument and see if it waits for 60 00:04:04,836 --> 00:04:06,183 a different period of time. 61 00:04:06,183 --> 00:04:09,094 We'll say wait(1,000) milliseconds, so 1 second. 62 00:04:09,094 --> 00:04:10,525 Save that. 63 00:04:11,558 --> 00:04:12,733 Try running it. 64 00:04:16,192 --> 00:04:18,937 And first, it waits for one second, and prints done. 65 00:04:18,937 --> 00:04:21,373 Then it waits for three seconds and prints done. 66 00:04:21,373 --> 00:04:25,904 So by adding a delay parameter to the weight method definition, we were able to 67 00:04:25,904 --> 00:04:30,110 pass arguments to our calls to wait, saying how long it should wait for.