Click here to Skip to main content
12,241,270 members (58,464 online)
Rate this:
Please Sign up or sign in to vote.
See more: C#
using System;
using System.Collections.Generic;
using System.Linq; 
namespace DemoApps
    public class PeopleLinQ
         public string FirstName { get; set; }
         public int Age { get; set; }
    public partial class MyPage
         protected void ProcessReq()
             List<peoplelinq> people = new List<peoplelinq>()
                 new PeopleLinQ() { FirstName = "abc", Age= 15},
                 new PeopleLinQ() { FirstName = "xyz", Age= 25}
            var peopleDataNew = from pep in people
                                 where pep.Age > 20
                                 select pep;
            people[1].FirstName = "Other New Name";
            foreach (var peopl in peopleDataNew)
                 peopl.FirstName = "SomeNew Name";
            var peopleData = from pep in people
                              where pep.Age > 20
                              select new
                                  OtherName = pep.FirstName,
                                  NewAge = pep.Age
            foreach (var peopl in peopleData)
                 Response.Write(peopl.OtherName + "<br />");

In the above code I want find people[1].FirstName as
people[1]."FirstName" or using variables

Please help
Thanks and regards
Posted 19-Nov-12 3:15am
Edited 19-Nov-12 20:49pm
Michiel du Toit 19-Nov-12 10:36am
Something like this maybe?

var lst = new List();

for (int i = 0; i < 5/*Number of columns*/; i++)
lst.Add(rd1["Param" + (i + 1).ToString()]);
Christian Graus 19-Nov-12 16:51pm
why does the value you look up change ? this whole setup looks odd to me, and like a hard to maintain hack. I think you need to explain why your data is in this format.
Programm3r 20-Nov-12 1:50am
Hi, Could you please be more specific towards what you are trying to achieve?

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You can use it

List<Dictionary<string, object>> people = new List<Dictionary<string, object>>()
                 new Dictionary<string,object>() {},
                 new Dictionary<string,object>() {}
            people[0].Add("Age", 15);
            people[1].Add("Age", 25);
            var peopleDataNew = from pep in people
                                where Convert.ToInt32(pep.["Age"]) > 20
                                select pep;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.160426.1 | Last Updated 20 Nov 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100