How to use conversion operators with linq query

By
The conversion operators are used to change the type of input objects.This provide a simple and convenient way for converting sequences to other collection types.In this tutorial ,we will learn about the ToList conversion operators.This is very help when you want to differentiate the different data types (int,char,string ,etc.) according to you(customer). This concepts will help you to do it.If you want to display each data type's data one by one in your application then it is more helpful to you.Please read it very care fully and use it in your application according to your goal.
There are some steps to implement this concepts in .net application as given below.  
Step 1:- First open your visual studio -->File -->New --> Select ASP.NET Empty website -->OK -->open solution Explorer --> Add New Web form (home.aspx) --> drag and drop List Box and button controls on the web page from toolbox as shown below:-


WEBFORM

Step 2:- Now Write write the following c# codes on button clicks (home.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 home : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    object[] list = { "ram", 1,'a', "shayam", 3,'b', 2, "mohan", 4, "rajkumar",'d','f', "schin", 5,"neha",8 };
    protected void Button1_Click(object sender, EventArgs e)
    {
        var n = list.OfType();
        ListBox1.Items.Add("The Integer values are:-");
        foreach (var int_num in n)
        {
            ListBox1.Items.Add(int_num.ToString());
        }

    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        var m = list.OfType();
        ListBox1.Items.Add("The character values are:-");
        foreach (var char_num in m)
        {
            ListBox1.Items.Add(char_num.ToString());
        }
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        var p = list.OfType();
        ListBox1.Items.Add("The string values are:-");
        foreach (var str_num in p)
        {
            ListBox1.Items.Add(str_num);
        }
    }
    protected void Button4_Click(object sender, EventArgs e)
    {
        ListBox1.Items.Clear();
    }
}

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


Note :- This concepts is useful for .net applications.You can use it according to you wherever you want to use it. 
Please share this post with your friends.
Download Attached application 
      Download

0 comments:

Post a comment

Powered by Blogger.