WHAT IS IENUMERABLE IN C#.

Ankit Singh

Total Post:341

Points:2389
Posted by  Ankit Singh
C# 
 554  View(s)
Ratings:
Rate this:

  I want to use IEnumerable In C# please give me solutions

  1. aditya kumar Patel

    Post:254

    Points:1810
    Re: What is IEnumerable In C#.

    The IEnumerable<T> is used to iterate a read only collection. It has only one method GetEnumeartor() which allows you to iterate the read only collection using a foreach loop. It only iterates in the forward direction.  IEnumerable <T> is defined in as follows:

    using System;

    using System.Collections.Generic;

    using System.Diagnostics;

    using System.Linq;

    using System.Net;

    using System.Text;

    using System.Threading;

    namespace Forum

    {

    public class ChildClass

    {

    static void Main(string[] args)

    {

    List<Customer> CustomerList = new List<Customer>();

    Customer obj = new Customer();

    obj.CustomerID = 1;

    obj.CustomerName = "Visal";

    obj.ContactNumber = "8787878787";

    CustomerList.Add(obj);

    obj = new Customer();

    obj.CustomerID = 1;

    obj.CustomerName = "Visal";

    obj.ContactNumber = "9797979797";

    CustomerList.Add(obj);

    obj = new Customer();

    obj.CustomerID = 1;

    obj.CustomerName = "Visal";

    obj.ContactNumber = "77986521322";

    CustomerList.Add(obj);

    IEnumerable<Customer> EnumList = CustomerList;

    foreach(Customer o in EnumList)

    {

    Console.WriteLine("CustomerID: {0}",o.CustomerID);

    Console.WriteLine("CustomerName: {0}", o.CustomerName);

    Console.WriteLine("ContactNumber: {0}", o.ContactNumber +"\n");

    }

    Console.ReadLine();

    }

    }

    public class Customer

    {

    public int CustomerID { get; set; }

    public String CustomerName { get; set; }

    public string ContactNumber { get; set; }

    }

    }

     

Answer

NEWSLETTER

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