lets consider this snippet of C# code:
List<string> a = new List<string>();
a.Add("word1");
a.Add("word2");
now lets say I want to have "word3" instead of word2. I can say
a[1]="word2";
but if I try
a.ElementAt(2) ="word2";
then I get an error saying the left hand side must be a variable.
this syntax behaves in the same way for reference types and value types. can someone explain why the second syntax is flawed?
setaccessor. Second thing is a method, which return some value.ElementAt, it will return you the element at the specified position.ElementAt(2)returns a string value,word2, and you are trying to assign to it, so you are doing the equivalent of"word2" = "word3", which isn't allowed. Assignments can only target variables, not values themselves.