LINQ Projection Operators (Select, SelectMany)

  Total Views : 361
  Comments : 0
 
  Keywords : what is projection operator in linq with example, Select / SelectMany projection operators in linq with examples, Different types of projection operators in linq with examples

Here we will learn projection operators in linq using c#, vb.net with example and different type of projection operators select, selectmany in linq with examples.

LINQ Projection Operators

In LINQ projection is an operation that transform an object into a new form that often consists only the properties which we used frequently.

Types of LINQ Projection Operators 

There are two types of projection operators in LINQ those are

 

  • Select
  • Select many

Following table shows the more detail regarding projection operators in LINQ.

 

OperatorDescriptionQuery Syntax
Select This operator projects values based on transform functions. select
SelectMany This operator projects sequence of values that are based on a transform function and then flatterns them into one sequence Use Multiple from Clauses

LINQ Select Projection Operator

In LINQ Select projection operator is used to select data from a collection. This LINQ select operator is same as SQL select clause.

 

Following is the syntax of using LINQ select projection operator to get data from collection.

 

C# Code

  

var result = from u in userslist

select u;

VB.NET Code

 

Dim result = From s In Objstudent

Select s

To know more about LINQ select projection operator check this LINQ Select Projection Operator with Example.

LINQ SelectMany Projection Operator

In LINQ SelectMany projection operator is used to select values from collection of collection.

 

Following is the syntax of using LINQ SelectMany projection operator.

 

C# Code

 

var Subjects = Objstudent.SelectMany(x => x.Subjects);

VB.NET Code

 

Dim Subjects = Objstudent.SelectMany(Function(x) x.Subjects)

To know more about LINQ SelectMany projection operator check this LINQ SelectMany Projection Operator with Example.

 Comments (0)

Be the first to give your valuable feedback

Leave a comment

  • Default Tutlane User