I have a reasonable dout,
ViewState .Add(....
or ViewState["XXXXX"]
is efficient ?
Eg.
1).
ViewState.Add("Example1", value );
2).
ViewState["Example1"]=value;
Both gives the same output, 1st one add the Value to the NameValueCollection
if that Key
does not exists.
2nd also does the same. Is there any difference in both. ?
There is no difference as far as performance. (Any trivial check is irrelevant to all other code execution.)
Add
will concatenate with existing values, however, as per the documentation.With this in mind, choose the most appropriate construct. In my mind, that is
ViewState[k] = v
in most circumstances -- unless of course the concatenation is desired.Happy coding.