如何查找List 内容并修改

wx9288 2017-11-04 02:22:22
Dim a1 As List(Of Tuple(Of Integer, Integer, Decimal)) = New List(Of Tuple(Of Integer, Integer, Decimal))

a1.Add((New Tuple(Of Integer, Integer, Decimal)(1 ,21, 3.3)))
a1.Add((New Tuple(Of Integer, Integer, Decimal)(2 ,33, 3.7)))
a1.Add((New Tuple(Of Integer, Integer, Decimal)(3 ,44, 4.0)))
a1.Add((New Tuple(Of Integer, Integer, Decimal)(4 ,66, 88.3)))

要查找a1 里面为 2 的数据,并将 33 和3.7 改为 其他数字 ,如123,88,6

代码要怎么写

...全文
845 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
threenewbee 2017-11-23
  • 打赏
  • 举报
回复
Dim a1 As List(Of Tuple(Of Integer, Integer, Decimal)) = New List(Of Tuple(Of Integer, Integer, Decimal)) a1.Add((New Tuple(Of Integer, Integer, Decimal)(1 ,21, 3.3))) a1.Add((New Tuple(Of Integer, Integer, Decimal)(2 ,33, 3.7))) a1.Add((New Tuple(Of Integer, Integer, Decimal)(3 ,44, 4.0))) a1.Add((New Tuple(Of Integer, Integer, Decimal)(4 ,66, 88.3))) Dim query = a1.Where(Function(x) x.Item1 = 2).First() query.Item2 = 123 query.Item3 = 88.6
清晨曦月 元老 2017-11-22
  • 打赏
  • 举报
回复
结构 & 类
  • 打赏
  • 举报
回复
a1.IndexOf("要查找的数据") ‘返回值为该数据在数组中的索引’ 然后在修改
正怒月神 2017-11-14
  • 打赏
  • 举报
回复
引用 4 楼 wx9288 的回复:
[quote=引用 1 楼 overown 的回复:] 既然需要到查找,那么一开始就应该使用便于查找的 Dictionary 而不要使用List
恩,最后发现LIST无法改值改成Dictionary 的,谢谢[/quote] list无法修改值,这个应该是你代码有问题。 下面是C#代码。但是原理上来说,只要找到这个对象的引用。不应该不能修改的。
public class User
        {
            public int id { get; set; }
            public virtual string name { get; set; }
            public virtual string buyer { get; set; }
            public virtual string idArr { get; set; }
        }

        static void Main(string[] args)
        {
            var q = new List<User>(){
            new User(){id=1,name="haha"},
            new User(){id=2,name="111"},
            };
            q[1].name = "hello my friend";

            q.ForEach(x => Console.WriteLine(x.name));

            Console.ReadLine();
        }
by_封爱 2017-11-14
  • 打赏
  • 举报
回复
list.find(d=>d==3)=4;
wx9288 2017-11-14
  • 打赏
  • 举报
回复
引用 1 楼 overown 的回复:
既然需要到查找,那么一开始就应该使用便于查找的 Dictionary 而不要使用List
恩,最后发现LIST无法改值改成Dictionary 的,谢谢
wx9288 2017-11-14
  • 打赏
  • 举报
回复
引用 2 楼 peng2739956 的回复:
这是VB?。
是的
peng2739956 2017-11-13
  • 打赏
  • 举报
回复
这是VB?。
ttsffgg 2017-11-13
  • 打赏
  • 举报
回复
既然需要到查找,那么一开始就应该使用便于查找的 Dictionary 而不要使用List

16,553

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧