From the course: .NET Essentials: Working with LINQ

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

The Empty and DefaultIfEmpty methods

The Empty and DefaultIfEmpty methods - .NET Tutorial

From the course: .NET Essentials: Working with LINQ

The Empty and DefaultIfEmpty methods

- [Instructor] The enumerable class has some methods that are used to generate data or empty resources. And that's what we're looking at in this chapter. So in this video, I'm going to look at empty and DefaultIfEmpty, empty's purpose is to return a zero length array of the type that you specified. So that's what I'm doing here on line eight. I want empty array of date times. And then here, I'm printing out the name of the array. How many items are in the array and the contents of the array? So what do we get? It's an array of date time. There's zero items in it. And when I attempt to print out the items, link passes there, there's nothing there, I can't iterate over it, there's nothing in it. Now, this always returns an array. So if you want a list what you have to do is use one of the other methods of the enumerable class that does conversion, so there's one called ToList so this generates an empty array of date times…

Contents