以参数形式获取列表项

以参数形式获取列表项

本文介绍了以参数形式获取列表项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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 />");
             }
 
        }
     }
 }



在上面的代码中,我想找人[1].名字为
people [1].名字"或使用变量


请帮忙
谢谢和问候
vilas



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


Please help
Thanks and regards
vilas

推荐答案

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;


这篇关于以参数形式获取列表项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 16:40