In one place i am using the list of string in that case the i am able to change the value of the string as code given below,
foreach(string item in itemlist.ToList())
{
item = someValue; //I am able to do this
}
But for object of class i am not able to alter the members value of the object the code is as below,
public class StudentDTO
{
string name;
int rollNo;
}
studentDTOList=GetDataFromDatabase();
foreach(StudentDTO student in studentDTOList.ToList())
{
student = ChangeName(student); //Not working
}
private StudentDTO ChangeName(StudentDTO studentDTO)
{
studentDTO.name = SomeName;
return studentDTO;
}
Error is : Can not assign because it's iteration variable
See Question&Answers more detail:os