Click here to Skip to main content
Rate this: bad
good
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
vilas
Posted 19-Nov-12 3:15am
Mogya1.6K
Edited 19-Nov-12 20:49pm
Programm3r11.3K
v4
Comments
Michiel du Toit at 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 at 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 at 20-Nov-12 1:50am
   
Hi, Could you please be more specific towards what you are trying to achieve?

1 solution

Rate this: bad
good
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("FirstName","abc");
            people[0].Add("Age", 15);
 
            people[1].Add("FirstName","xyz");
            people[1].Add("Age", 25);
 
            var peopleDataNew = from pep in people
                                where Convert.ToInt32(pep.["Age"]) > 20
                                select pep;
  Permalink  
v4

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

  Print Answers RSS
0 OriginalGriff 350
1 Jochen Arndt 190
2 Richard MacCutchan 135
3 Sergey Alexandrovich Kryukov 130
4 DamithSL 105
0 OriginalGriff 6,045
1 DamithSL 4,601
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,310


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 20 Nov 2012
Copyright © CodeProject, 1999-2014
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