How to use ZIP Operator Concepts in LINQ

By
Hi friend, Today, i am going to explain "How to implement Zip operator concepts in Linq".You can easily implement this concepts in your projects. The Zip operator parses the elements at the same index position in each sequence. It reruns the result when one of the sequences finishes reading the element .It is helpful to write sort code in programs. i have explained this concepts with an example. you can implement it on your visual studio.
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 List Box and Button Controls on the form as shown below:-


form

Step 2 :- Now Write the C# codes  in default.aspx.cs file as given below:-
using System;
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[] names = new string[] { "Dog", "Cat", "Cow", "Goat", "Hen" };
        string[] position = new string[] { "strong pet", "weak pet", "very strong pet", "small pet","weak pet" };
        int[] Ages = new int[] { 10, 15, 20, 5, 7 };
        var m = names.Zip(position,(p,q)=>"This "+ p + " is a " +q+ " in india");
        var n = m.Zip(Ages,(r,s)=> r+ " with " +s+" years old. ");
        foreach (var res in n)
        {
            ListBox1.Items.Add(res);
        }
    }
}


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



For More...

  1. Introduction of MVC Concepts
  2. Introduction of PLINQ Concepts
  3. Grouping and sorting operators in LINQ
  4. How to run linq query against array and List
  5. How to use projection operator in linq

Download Whole Attached File
       Download

0 comments:

Post a Comment

Powered by Blogger.