简体   繁体   English

indexof自定义列表的功能

[英]indexof function for a custom list

I need to update an entry in a custom list which i created, the list is shown below: 我需要更新我创建的自定义列表中的条目,列表如下所示:
List<Data> Test = new List<Data>();
I found some solutions proposed online such as using FindIndex , however this function is not present. 我发现了一些在线提出的解决方案,比如使用FindIndex ,但是这个功能不存在。
Note: I'm using C# in windows phone 7 development if this helps. 注意:如果这有帮助,我在Windows Phone 7开发中使用C#
Thanks 谢谢

If you don't want to find the object by an index, but by some field inside your class, you could do something like this. 如果您不想通过索引找到对象,而是通过类中的某个字段找到对象,则可以执行类似的操作。 I'm assuming your DATA object has a unique ID field inside it... 我假设你的DATA对象里面有一个唯一的ID字段......

var someName = "name_i_want_to_find";
var myItems = Test.FindAll(x => x.Name == someName);

foreach (var item in myItems)
    item.FieldToChange = "someNewValue";

List有一个IndexOf方法,它存在于Windows Phone 7版本中。

Use IndexOf() method directly. 直接使用IndexOf()方法。 MSDN MSDN

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM