I’ve been wondering which is faster (or if it even makes a difference), referencing a textbox’s Text property or a string assigned to that value?
Ref textbox.Text
if(textbox1.Text == "A")
{ //do a million iterations
}
Or
string aString = textbox1.Text;
if(aString == "A")
{ //do a million iterations
}
I made just a quick analyze using stop watch: 10.000.000 iterations.
In first case it returns to me: 00:00:21.56
In second case it returns to me: 00:00:42.62
In second case you have Get accessor + new pointer to string every iteration, so its slower.
Hope this helps.
EDIT
I put all code of any case inside the iteration. Seems that is the quetion.