how to change an item in IQueryable<T>?
i have a the following class :
class myClass { string b; string c; string d; }
and the following list :
IQueryable<myClass> bla = new list<myClass>();
i want to change the first item in the list where开发者_JAVA技巧 myClass.c = "kitten";
To another instance of myClass lets call him newInstance;
i don't want to do k = bla.first(x => x.c =="kitten") and then copy one by one the fields from newInstance to k, i want the "bla" list to refernce to newInstance, without changing k..
how do i achieve it ?
You can use below iterator to do this:
public static IEnumerable<myClass> GetChanged(IEnumerable<myClass> data)
{
bool found = false;
foreach(myClass c in data)
{
if(found == false && c.c=="kitten")
{
found = true;
yield return new myClass() ; //new object
}
else
yield return c;
}
}
精彩评论