1 00:00:00,670 --> 00:00:05,465 We'll need to add the using directives for system.collections.generic and 2 00:00:05,465 --> 00:00:07,340 system.link to this file. 3 00:00:09,410 --> 00:00:18,790 Using System.Collections.Generic and using System. 4 00:00:20,000 --> 00:00:20,500 Link. 5 00:00:23,180 --> 00:00:25,170 Let's put our search feature to work and 6 00:00:25,170 --> 00:00:28,600 try to figure out what the bird was that I saw the other day. 7 00:00:29,690 --> 00:00:33,430 We can write a little console application that will cycle through each page of 8 00:00:33,430 --> 00:00:36,630 the results until we press a certain key. 9 00:00:36,630 --> 00:00:39,785 So let's hop over to the program.cs file. 10 00:00:41,745 --> 00:00:45,400 First, let's create our search parameters. 11 00:00:45,400 --> 00:00:52,550 var searchParameters= new BirdSearch. 12 00:00:52,550 --> 00:00:57,019 So we'll use object initialization here. 13 00:00:59,941 --> 00:01:06,694 And so the bird was Size = medium and 14 00:01:06,694 --> 00:01:13,672 The country was the United States and 15 00:01:13,672 --> 00:01:18,400 the colors we have to give 16 00:01:18,400 --> 00:01:23,127 it a new list of string and 17 00:01:23,127 --> 00:01:27,630 the colors were White, 18 00:01:27,630 --> 00:01:31,029 Brown and Black. 19 00:01:32,570 --> 00:01:36,446 Okay, and then the page will give it zero to start out. 20 00:01:40,815 --> 00:01:47,690 And the page size will give it, what did I say earlier a five, all right. 21 00:01:49,200 --> 00:01:51,070 So we've got our search parameters. 22 00:01:53,250 --> 00:01:56,634 Let's write something to the console so they know what's going on. 23 00:01:56,634 --> 00:02:03,093 Console.WriteLine Type any key to begin search. 24 00:02:03,093 --> 00:02:07,490 Kinda like a go button, right? 25 00:02:09,010 --> 00:02:13,120 All right, now we're gonna need a loop to loop through our results. 26 00:02:13,120 --> 00:02:18,540 While Console.ReadKey, 27 00:02:18,540 --> 00:02:22,020 so that'll read only one key at the console. 28 00:02:22,020 --> 00:02:25,020 And it has a property called KeyChar. 29 00:02:26,300 --> 00:02:29,432 And if that is not equal to q, we'll say. 30 00:02:33,445 --> 00:02:33,945 Okay. 31 00:02:35,220 --> 00:02:38,410 So this loop is going to keep looping and 32 00:02:38,410 --> 00:02:44,520 reading a key from a console until somebody presses a q. 33 00:02:44,520 --> 00:02:46,310 First, let's write out something to the console. 34 00:02:48,240 --> 00:02:53,085 I'm going to use a new feature of c sharp instead of using 35 00:02:53,085 --> 00:02:56,670 string.format like we have in previous videos. 36 00:02:56,670 --> 00:03:01,780 I'm gonna use a dollar sign, then a string quote. 37 00:03:01,780 --> 00:03:08,810 Inside here, I'm gonna say Page colon, and open close curly braces. 38 00:03:10,290 --> 00:03:14,740 So when I put this dollar sign right here, inside the curly braces, 39 00:03:14,740 --> 00:03:16,110 I can put in code. 40 00:03:16,110 --> 00:03:21,320 So we'll use our searchParameters .Page. 41 00:03:21,320 --> 00:03:24,390 So we're going to let whoever's at the console know what page they're on. 42 00:03:28,010 --> 00:03:33,866 Then, I think we need to use our search on birds but 43 00:03:33,866 --> 00:03:40,141 we don't have a list of birds so we'll create a new var 44 00:03:40,141 --> 00:03:46,425 birds one last time = BirdRepository.LoadBirds. 45 00:03:49,458 --> 00:03:54,942 Okay, and now we can call our search method .search and 46 00:03:54,942 --> 00:04:00,778 we'll pass it the searchParameters search parameters And 47 00:04:00,778 --> 00:04:05,562 then will just well call ToList put it in a list and 48 00:04:05,562 --> 00:04:11,300 there's an other method I wanna show you called ForEach. 49 00:04:12,760 --> 00:04:15,130 And what this does we can pass it on lambda. 50 00:04:16,540 --> 00:04:24,320 goes to and what that does is run a piece of code for every element in the list. 51 00:04:24,320 --> 00:04:28,190 So for each b in birds, 52 00:04:28,190 --> 00:04:32,560 let's write out to the console, console.WriteLine. 53 00:04:32,560 --> 00:04:37,580 And we'll do that magic string mashing thing again. 54 00:04:38,670 --> 00:04:41,280 We'll start out with a dollar sign. 55 00:04:41,280 --> 00:04:44,950 I like to go ahead and quote, quote end my method just so 56 00:04:44,950 --> 00:04:46,940 I don't have any syntax errors. 57 00:04:46,940 --> 00:04:51,710 So in here we're going to write the name of the bird Common Name 58 00:04:53,260 --> 00:04:55,286 equals and then we need our curly braces. 59 00:04:55,286 --> 00:05:03,740 So that's b.CommonName because our b Is our input parameter for a lambda. 60 00:05:06,320 --> 00:05:11,740 All right, and we need to close out the for each method. 61 00:05:14,370 --> 00:05:18,950 So while this is looping, it's not gonna change the page. 62 00:05:18,950 --> 00:05:23,650 We need to change the page after every time we print them out to the screen. 63 00:05:23,650 --> 00:05:32,260 So let's search parameters every time we loop through, we'll add to the page. 64 00:05:32,260 --> 00:05:32,910 Page, plus plus. 65 00:05:32,910 --> 00:05:34,690 So, we'll add one to the page property. 66 00:05:36,810 --> 00:05:38,130 Okay. 67 00:05:38,130 --> 00:05:41,430 So I think we can go ahead and compile this guy. 68 00:05:41,430 --> 00:05:44,770 So we're going to compile on the console with mcs. 69 00:05:44,770 --> 00:05:47,570 All of our files with star.cs. 70 00:05:47,570 --> 00:05:56,000 Then we're gonna specify the out argument and we're gonna give it Program.exe. 71 00:05:56,000 --> 00:06:00,465 So that it'll compile all our files and give us an executable called 72 00:06:00,465 --> 00:06:05,388 Program.exe, we've got an error. 73 00:06:05,388 --> 00:06:07,360 Bird search extension.cs. 74 00:06:07,360 --> 00:06:09,363 Let's go check that out. 75 00:06:11,334 --> 00:06:16,580 Line 22 oops looks like we've got a couple of typos here 76 00:06:16,580 --> 00:06:21,400 where s.size and search should have been an a in it. 77 00:06:22,410 --> 00:06:23,740 Did you catch that before I did? 78 00:06:23,740 --> 00:06:28,270 All right, we'll save that file and we'll try it again. 79 00:06:30,910 --> 00:06:31,470 Okay. 80 00:06:33,350 --> 00:06:38,030 BirdSearchExtension, the name page does not exist. 81 00:06:38,030 --> 00:06:40,676 That's line 29. 82 00:06:40,676 --> 00:06:41,540 Ha. 83 00:06:41,540 --> 00:06:44,332 I put in just random variable names here. 84 00:06:48,311 --> 00:06:54,961 This should be search.Page and 85 00:06:54,961 --> 00:07:02,349 this should be search.PageSize, 86 00:07:02,349 --> 00:07:09,010 okay, and search.PageSize. 87 00:07:09,010 --> 00:07:11,608 All right, let's try to compile again. 88 00:07:15,679 --> 00:07:20,327 All right great, so now we can run 89 00:07:20,327 --> 00:07:24,670 this with mono Program.exe. 90 00:07:24,670 --> 00:07:27,330 Okay, type any key to begin search. 91 00:07:28,730 --> 00:07:31,935 All right, there's our first page could be any of those. 92 00:07:31,935 --> 00:07:36,810 [LAUGH] All right. 93 00:07:36,810 --> 00:07:38,840 2, 3. It looks like we've run out of 94 00:07:38,840 --> 00:07:39,680 bird results. 95 00:07:40,800 --> 00:07:42,220 Now, I'll press q to exit. 96 00:07:43,860 --> 00:07:44,426 Awesome.