How to use projection operators with Linq

The projection operator is a very important concepts used in LINQ. The SelectMany() and Select () function are the type of projection operator which are used to define a projection to select values of the result based on a selector function (Ex. split()). In this tutorial i have used split() function to split the words from given strings. Here i have used select () clause for this purpose.You can use the SelectMany() clause to display the data.In this, i have  splitted the words from the strings where i  found the blank space in the sentence.  
There are some steps to implement this concepts as given below:-
Step 1 :- First open your visual studio --> File --> New --> Website -->Select ASP.NET Empty Website--> OK --> Open Solution Explorer -->Add a New web Form (Default.aspx)--> Drag and Drop ListBox and Button control  on the page from toolbox as given below:-


Step 2 :- Now write the C# codes on Submit Button clicks (Default.aspx.cs) as given below:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)

    protected void Button1_Click(object sender, EventArgs e)
        string[] str = new string[] { "This is", "You can learn lot of things from here", "Now days .NET is more important in development" };
        IEnumerable values = str.Select(s => s.Split(' '));
        foreach (string[] data in values)
            foreach (string value1 in data)

Step 3 :- Now Run the application (press F5)--> You will see the following output as shown below:-

Note :- You can use this concepts in your real life projects.

You can run this whole application on your system after download it from below.
Please share this application and help to other students also. 
Download Attached File


Post a Comment

Powered by Blogger.