如何编辑列表中的项目:C#和WPF

如何编辑列表中的项目:C#和WPF,c#,wpf,list,C#,Wpf,List,好的,我已经学习了如何创建列表、查看列表中的项目以及使用列表中的项目。我现在想学习如何编辑列表中的信息 以下是我的清单: class ObjectProperties { public string ObjectNumber { get; set; } public string ObjectComments { get; set; } public string ObjectAddress { get;

好的,我已经学习了如何创建列表、查看列表中的项目以及使用列表中的项目。我现在想学习如何编辑列表中的信息

以下是我的清单:

 class ObjectProperties
        {
            public string ObjectNumber { get; set; }
            public string ObjectComments { get; set; }
            public string ObjectAddress { get; set; }


        }

        List<ObjectProperties> Properties = new List<ObjectProperties>();

我希望用户使用文本框(txtUpdateObjectNumber)输入要更新的号码。然后,我想将该数字与record.ObjectNumber中存储的值进行比较,如果存在,我想替换record.ObjectNumber和record.ObjectComments中的信息,其中record.ObjectNumber==txtUpdateObjectNumber。如果你需要我详细说明什么,请告诉我。任何帮助都将不胜感激。谢谢:)

要查找列表项,请使用linq:

ObjectProperties opFound = Properties.Find(x => x.ObjectNumber == txtUpdateObjectNumber.Text);
或委托表格:

ObjectProperties opFound = Properties.Find(delegate (ObjectProperties x) { return x.ObjectNumber == txtUpdateObjectNumber.Text; });

一旦您在列表中找到该项,您对
opFound
所做的任何更改,包括
ObjectNumber
,都将保留在列表中。

根据您所说的,在我看来,您最好使用
字典()
…加上您的“ObjectNumber”可能更好地用int表示,或uint。但对象编号必须能够更改..:/你知道一旦我这样做了,我会改变列表中的值吗?这将返回
ObjectProperties
对象;您对该属性所做的任何更改都将保留在列表中。哦,好的。我试试看:)谢谢。
ObjectProperties opFound = Properties.Find(delegate (ObjectProperties x) { return x.ObjectNumber == txtUpdateObjectNumber.Text; });