by
Roland Schumacher alias GENiALi
21. April 2008 -- 166
words -- 1 mal gelesen
This was the question.
Which of the following code samples is the most efficient and compiles correctly?
The following answers were available.
1.
string s = null;
StringBuilder sb = null; SB.Append("Hello"); SB.Append(",_"); SB.Append("World"); SB.Append("!"); s = sb.ToString();
2.
string s = null;
StringBuilder sb = null; SB = "Hello"; sb += ", "; SB += "World"; sb += "!"; s = sb.ToString();
3.
string s = null;
s = "Hello";
s += ", ";
s += "World"; s += "!";
4.
string s = null;
s = "Hello";
s += ", ";
s += "World"; s += "!";
For me it was clear, it must be 3 or 4. But I find there
no difference.1 can not be. StringBuilder is null
and there you can do not append. 2 The StringBuilder is
incorrectly applied.
1 Was right. How so? It is efficient and can compile.
But do not. This was also the question.
I hate such questions.
8db4f8e5-8869-4407-b581-8366b09879e1|0|.0
Tags: