我有一个object
它有一些属性,其中一些属性是Lists
. 每个列表都包含其他类的实例。我想要做的是从列表中取出第一项并覆盖这些属性值。
这是我所拥有的一个伪示例:
public class User
{
public List<Address> Addresses = new List<Address>();
public User ( )
{
Addresses = fill with data;
}
}
public class TestUser
{
public User user; // Is filled somewhere in this class
public void TestUpdateList ( Address addr )
{
// The param "addr" contains new values
// These values must ALWAYS be placed in the first item
// of the "Addresses" list.
// Get the first Address object and overwrite that with
// the new "addr" object
user.Addresses[0] = addr; // <-- doesn't work, but should give you an idea
}
}
我希望这个例子能阐明我想做的事情。
所以我基本上是在寻找一种方法来“更新”列表中的现有项目,在这种情况下是一个object
.