USE SELECT OPERATOR IN LINQ.

Norman Reedus

Total Post:45

Points:315
Posted by  Norman Reedus
LINQ 
 493  View(s)
Ratings:
Rate this:
We want to use Select Operator in linq. How to do this please help me.
  1. aditya kumar Patel

    Post:254

    Points:1810
    Re: Use Select Operator in linq.

    The Select operator always returns an IEnumerable collection which contains elements based on a transformation function. It is similar to the Select clause of SQL that produces a flat result set.

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Text;

    namespace Prototype

    {

    class Example

    {

    static void Main()

    {

    IList<Employee> empList = new List<Employee>() {

    new Employee() { ID = 1, EmpName = "Rohit", Age = 13 } ,

    new Employee() { ID = 2, EmpName = "Monu", Age = 21 } ,

    new Employee() { ID = 3, EmpName = "Mohsan", Age = 18 } ,

    new Employee() { ID = 4, EmpName = "Sohel" , Age = 20 } ,

    new Employee() { ID = 5, EmpName = "Arun" , Age = 20 } ,

    new Employee() { ID = 6, EmpName = "Karan" , Age = 25 }

    };

    var selectResult = from s in empList

    select new { Name = "Mr. " + s.EmpName, Age = s.Age };

    foreach (var item in selectResult)

    Console.WriteLine("Student Name: {0}, Age: {1}", item.Name, item.Age);

    Console.ReadLine();

    }

    }

    class Employee

    {

    public int ID { get; set; }

    public string EmpName { get; set; }

    public int Age { get; set; }

    }

    }

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!