I wrote a method-extension for to simualte List's First()
but the returned value (actually reference, isn't?) doesn't work if I try to change a property of it, for example;
HtmlElement ele = webBrowser1.Document.All.GetElementsByName("foo").First();
ele.InnerText = "hello!"; // doesn't Works. That value isn't changed. Why?
webBrowser1.Document.All.GetElementsByName("foo")[0].InnerText = "abc"; // but this does Works
Here's First()
function:
public static HtmlElement First(this HtmlElementCollection a)
{
if (a == null)
throw new ArgumentNullException();
if (a.Count == 0)
throw new InvalidOperationException();
return a[0];
}
Why using return from a.First().value = foo
doesn't Works but arr[0].value = "hehe";
does? how do I fix it? do I need to learn how to use returns ref
?