可能更新List(类的类型)只是类的一部分吗? [英] It is possible update List (type of class) only part of class?

查看:96
本文介绍了可能更新List(类的类型)只是类的一部分吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好b $ b

我有一个清单。 List是一个类型类(MyClass)。 MyClass具有相同的属性(例如名称和描述 - 两种类型的字符串)。

我填充列表(名称和描述)。后来我只想更新说明。这个描述我有List(字符串的类型)。

可能没有FOREACH的更新列表(不需要填充这两个属性)?

两个列表都有相同的大小(aaaa和NewDecsr)。



Hi
I have a List. List is a type class (MyClass). MyClass have same attribute (e.g. Name and Description - both type of string).
I fill List (Name and Description). Later I want update only Description. This Description I have in List (type of string).
It is possible update List without FOREACH (without need fill both attributes)?
Both List have same size (aaaa and NewDecsr).

class MyClass
{
    public string Name { get; set; }
    public string Descr { get; set; }
}




List<myclass> aaaa = new List<myclass>();
....




List<string> NewDescr = new List<string>();
....



这样的东西?


Something like this?

aaaa[].Descr = NewDesc;





谢谢



Thank you

推荐答案

是这样的吗?

Is something like this?
for (int i = 0; i< aaaa.Count; i++)
{
    aaaa[i].Descr = NewDescr[i].Descr;
}


只是摆弄,所以无需投票

Just fiddling around, so no need to vote
var toSkip = 0;

aaaa.ForEach(simpleClass => {
    simpleClass.Title = NewDescr.Skip(toSkip++).First();
});



只是古玩,否则可以实现:)


just curios, could it be achieved otherwise :)


这篇关于可能更新List(类的类型)只是类的一部分吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆