Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Updated 19-Nov-12 19:49pm
v4
Comments
Michiel du Toit 19-Nov-12 10:36am    
Something like this maybe?

var lst = new List<string>();

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

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;
 
Share this answer
 
v4

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900