1 00:00:00,850 --> 00:00:04,440 Make sure you've got our birds list loaded in this C# REPL for this video. 2 00:00:06,130 --> 00:00:09,310 Most of our LINQ operators return an Enumerable, 3 00:00:09,310 --> 00:00:13,740 what if we needed to be something else like a list or an array? 4 00:00:13,740 --> 00:00:17,395 The one I use most often is ToList, 5 00:00:17,395 --> 00:00:22,215 birds.Where b goes to 6 00:00:22,215 --> 00:00:29,225 b.color equals Red and then I will call ToList. 7 00:00:31,890 --> 00:00:34,860 Its usefulness might not be apparent though, 8 00:00:34,860 --> 00:00:37,970 remember when we talked about deferred execution. 9 00:00:37,970 --> 00:00:42,300 Since we're in the C# REPL, our queries are getting evaluated immediately. 10 00:00:43,400 --> 00:00:49,429 If we assign a LINQ expression to a variable, 11 00:00:49,429 --> 00:00:58,169 var redBirds equals birds.Where b goes to b.Color equals Red. 12 00:00:58,169 --> 00:01:04,910 It doesn't get evaluated until we iterate on it. 13 00:01:04,910 --> 00:01:08,550 So calling ToList or any of the other conversion operators 14 00:01:08,550 --> 00:01:11,230 iterates through the sequence to produce the result. 15 00:01:11,230 --> 00:01:13,866 And so our query is executed. 16 00:01:13,866 --> 00:01:19,490 RedBirds.ToList. 17 00:01:19,490 --> 00:01:21,470 Similarly, there's ToArray. 18 00:01:21,470 --> 00:01:27,420 RedBirds.ToArray and now we have an array. 19 00:01:28,720 --> 00:01:32,692 There's a few more conversion operators that can be useful in some edge cases, 20 00:01:32,692 --> 00:01:35,800 like if you need a lookup or a dictionary. 21 00:01:35,800 --> 00:01:37,860 I've linked to those in the notes. 22 00:01:37,860 --> 00:01:41,230 You should check them out and think about how you could use them in a LINQ query. 23 00:01:43,350 --> 00:01:46,160 >> Wow, that's a lot of operators we just used. 24 00:01:46,160 --> 00:01:47,630 Did you take notes? 25 00:01:47,630 --> 00:01:52,730 I find myself constantly looking up syntax and documentation on LINQ operators, 26 00:01:52,730 --> 00:01:55,750 especially for ones I don't use very often. 27 00:01:55,750 --> 00:01:59,380 We learn to use quantifiers to see if a sequence contains 28 00:01:59,380 --> 00:02:01,640 elements that fit a condition. 29 00:02:01,640 --> 00:02:05,830 Element operators to pick single elements out of a sequence. 30 00:02:05,830 --> 00:02:10,390 We use partitioning operators to obtain a subset of a sequence and 31 00:02:10,390 --> 00:02:13,840 joins to join multiple sequences together. 32 00:02:13,840 --> 00:02:17,730 We performed aggregations to analyze our sequences. 33 00:02:17,730 --> 00:02:23,530 We use set operations to remove duplicates and merge separate sequences into one. 34 00:02:23,530 --> 00:02:27,160 We then learned we can use LINQ to generate sequences and 35 00:02:27,160 --> 00:02:30,370 finally, to convert them to different types of sequences. 36 00:02:31,640 --> 00:02:34,480 We've been working in workspaces this whole time. 37 00:02:34,480 --> 00:02:39,170 You'll find that as you advance to coding in an IDE like Visual Studio. 38 00:02:39,170 --> 00:02:42,450 The built in features will help you remember the usage without having 39 00:02:42,450 --> 00:02:44,550 to look up the documentation. 40 00:02:44,550 --> 00:02:47,420 Let's take a quick peek at how using an IDE 41 00:02:47,420 --> 00:02:50,250 can help us jog our memories when writing LINQ queries. 42 00:02:52,000 --> 00:02:55,336 >> I've got a blank console application here in Visual Studio, 43 00:02:55,336 --> 00:02:58,170 let's create a list of numbers like we did earlier. 44 00:02:58,170 --> 00:03:05,075 Var numbers equals new list of int and 45 00:03:05,075 --> 00:03:10,421 we'll initialize it, 2, 46 00:03:10,421 --> 00:03:16,231 4, 8, 16, 32, 64. 47 00:03:18,351 --> 00:03:21,880 Okay, so we don't have the System.Linq namespace. 48 00:03:23,040 --> 00:03:26,660 Let's look at what Visual Studio's IntelliSense tells us we can call 49 00:03:26,660 --> 00:03:27,870 on the numbers variable. 50 00:03:29,580 --> 00:03:34,010 So you'll notice we don't have any of the LINQ methods we've been using. 51 00:03:34,010 --> 00:03:38,380 Just the normal list methods, so 52 00:03:38,380 --> 00:03:45,886 let's add the System.Linq namespace using System.Linq. 53 00:03:45,886 --> 00:03:53,100 Now, I'll type a period and it gives us a lot more methods, look at all those. 54 00:03:54,380 --> 00:03:57,040 So notice the little arrow icon right here. 55 00:03:57,040 --> 00:04:02,631 If I click on this, that arrow is indicating that it's an extension method. 56 00:04:02,631 --> 00:04:07,132 And you can see here that we've got the definition and 57 00:04:07,132 --> 00:04:09,640 the syntax for each of these. 58 00:04:12,490 --> 00:04:16,399 Let's call the Where operator, we've used that a lot. 59 00:04:18,790 --> 00:04:26,760 Where n goes to n is greater than 10. 60 00:04:26,760 --> 00:04:28,520 If I hover over the n here, 61 00:04:28,520 --> 00:04:31,430 notice that it's telling me the n parameter is an integer. 62 00:04:31,430 --> 00:04:33,280 How helpful is that? 63 00:04:33,280 --> 00:04:36,030 It can be really useful when writing LINQ queries. 64 00:04:36,030 --> 00:04:40,190 So you see how Visual Studio gives us a lot of documentation, so 65 00:04:40,190 --> 00:04:42,730 we don't necessarily have to go and find it ourselves. 66 00:04:42,730 --> 00:04:43,590 What a huge help.