Showing posts with label Class object array loop. Show all posts
Showing posts with label Class object array loop. Show all posts

Wednesday, December 22, 2010

Linq to class objects

This example shows how to use the array of class object and its variables on run time using "LINQ".
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
public class LinqClass
{
    public string Name;
    public string contact;
    public string city;

}

using System.Xml;
using System.Xml.Linq;
using System.Linq;
using System.Data;

var sp = new[] {
          new LinqClass { Name="Murugesan",
                          contact="9769104815",
                          city="Chennai"
                        },
                        new LinqClass { Name="Pandian",
                                        city="Madurai",
                                        contact="9786466642"
                                      }
          };
        foreach (var n in sp)
        { 
            Response.Write(n.Name.ToString());
        }