J
Jiho Han
Which is faster?
int x = 5;
string v = String.Format("{0}", x);
or
string v = x.ToString();
Looking at it, it seems almost obvious that the latter would be faster since
the first would involve creating a new string object and formatting - even
if simple. I just wanted to know if anyone else have comments.
Here's another:
int increment = 0;
string controlname = "abc";
string v = String.Format("{0}{1}", controlname, increment);
or
string v = controlname + increment.ToString();
or
StringBuilder sb = new StringBuilder();
sb.AppendFormat("{0}{1}", controlname, incremenet);
string v = sb.ToString();
I wonder whether String.Format is internally implemented as the last bit of
code snippet.
I'd appreciate any thoughts on these items. I use all of these approaches
everywhere and I often wonder if I am doing the right thing.
Thanks much.
Jiho Han
int x = 5;
string v = String.Format("{0}", x);
or
string v = x.ToString();
Looking at it, it seems almost obvious that the latter would be faster since
the first would involve creating a new string object and formatting - even
if simple. I just wanted to know if anyone else have comments.
Here's another:
int increment = 0;
string controlname = "abc";
string v = String.Format("{0}{1}", controlname, increment);
or
string v = controlname + increment.ToString();
or
StringBuilder sb = new StringBuilder();
sb.AppendFormat("{0}{1}", controlname, incremenet);
string v = sb.ToString();
I wonder whether String.Format is internally implemented as the last bit of
code snippet.
I'd appreciate any thoughts on these items. I use all of these approaches
everywhere and I often wonder if I am doing the right thing.
Thanks much.
Jiho Han