LINQ Empty Method

  Total Views : 134
  Comments : 0
 
  Keywords : Linq empty operator in c# / vb.net with example, How to use linq empty method to empty the collection sequence in c# / vb.net with example, Linq enumerable.empty() method in c# / vb.net

Here we will learn LINQ Empty method in c#, vb.net with example and how to use LINQ Empty method to empty the collection sequence in c#, vb.net with example.

LINQ Empty Method

In LINQ Empty method or operator is used to return an empty sequence of collection.

Syntax of LINQ Empty Method

Following is the syntax of LINQ Empty method to generate collection with empty sequence.

 

C# Code

 

var result = Enumerable.Empty<int>();

VB.NET Code

 

Dim result = Enumerable.Empty(OfInteger)()

If you observe above syntax we defined Empty method to generate empty sequence.

Example of LINQ Empty Method

Following is the example of LINQ Empty method to generate a collection that contains empty sequence.

 

C# Code

 

using System;

using System.Linq;

 

namespace Linqtutorials

{

class Program

{

static void Main(string[] args)

{

var result = Enumerable.Empty<int>();

foreach (var item in result)

{

Console.WriteLine(item);

}

Console.ReadLine();

}

}

}

VB.NET Code

 

Module Module1

Sub Main()

Dim result = Enumerable.Empty(Of Integer)()

For Each item In result

Console.WriteLine(item)

Next

Console.ReadLine()

End Sub

End Module

If you observe above example we defined Empty method to generate empty sequence. If we run above example we will get empty results. This is how we can use LINQ Empty method to generate empty sequence of collection.

 
 

NEXT

LINQ to Objects  
 

 Comments (0)

Be the first to give your valuable feedback

Leave a comment

  • Default Tutlane User