{"id":402,"date":"2011-12-01T21:14:25","date_gmt":"2011-12-01T21:14:25","guid":{"rendered":"http:\/\/devnot.wordpress.com\/?p=402"},"modified":"2011-12-01T21:14:25","modified_gmt":"2011-12-01T21:14:25","slug":"cannot-modify-the-return-value-of-system-collections-generic-list-thisint-because-it-is-not-a-variable","status":"publish","type":"post","link":"https:\/\/thomas-jansen.eu\/?p=402","title":{"rendered":"Cannot modify the return value of System.Collections.Generic.List.this[int]\u2018 because it is not a variable"},"content":{"rendered":"<p>This error is shown when an attempt to assign a value to a property inside a struct.<\/p>\n<p>e.g<\/p>\n<p>System.Drawing.Point p = new Point();<br \/>\np.X = 1; \/\/legal of course<\/p>\n<p>Listlist = new List();<br \/>\nlist.Add(p);<br \/>\nlist[0].X = 123; \/\/Cannot modify the return value of System.Collections.Generic.List.this[int]\u2018 because it is not a variable<\/p>\n<p>Remember structs are value types. They are processed like integers and only assigned as a whole.<br \/>\nTherefore when accessed from a list a copy of the struct is returned. Assigning to the copy is pointless, hence the error. <\/p>\n<p>You can assign one member by using the following method<\/p>\n<p>System.Drawing.Point p = list[0];<br \/>\np.X = 123;<br \/>\nlist[0] = p;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This error is shown when an attempt to assign a value to a property inside a struct. e.g System.Drawing.Point p = new Point(); p.X = 1; \/\/legal of course Listlist = new List(); list.Add(p); list[0].X = 123; \/\/Cannot modify the return value of System.Collections.Generic.List.this[int]\u2018 because it is not a variable Remember structs are value types. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-402","post","type-post","status-publish","format-standard","hentry","category-c"],"_links":{"self":[{"href":"https:\/\/thomas-jansen.eu\/index.php?rest_route=\/wp\/v2\/posts\/402","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thomas-jansen.eu\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thomas-jansen.eu\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thomas-jansen.eu\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/thomas-jansen.eu\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=402"}],"version-history":[{"count":0,"href":"https:\/\/thomas-jansen.eu\/index.php?rest_route=\/wp\/v2\/posts\/402\/revisions"}],"wp:attachment":[{"href":"https:\/\/thomas-jansen.eu\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=402"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thomas-jansen.eu\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=402"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thomas-jansen.eu\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=402"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}