T
Trevor
I have a couple of questions regarding C# strings.
1) Sometimes I see a string in someone else's code like:
string foo = @"bar";
What does the '@' do for you?
2) Is there a performance loss if I start concatenating strings together
with the + operator ? In Java, they discouraged code like this:
string command = "CMD " + var1 + " " + var2;
The reason is because of all of the temporary String objects that get
created in the meantime. The solution is to use a StringBuffer like so:
StringBuffer command = new StringBuffer("CMD ");
command.append(var1);
command.append(' ');
command.append(var2);
System.out.println(command.toString());
This is less expensive than the above code because String objects are not
being created left & right. Does C# have the same problem? I noticed that
C# has a StringBuilder class which is just like the Java StringBuffer class.
Should I use StringBuffer in cases like the above where I need to
concatenate multiple strings to one string?
1) Sometimes I see a string in someone else's code like:
string foo = @"bar";
What does the '@' do for you?
2) Is there a performance loss if I start concatenating strings together
with the + operator ? In Java, they discouraged code like this:
string command = "CMD " + var1 + " " + var2;
The reason is because of all of the temporary String objects that get
created in the meantime. The solution is to use a StringBuffer like so:
StringBuffer command = new StringBuffer("CMD ");
command.append(var1);
command.append(' ');
command.append(var2);
System.out.println(command.toString());
This is less expensive than the above code because String objects are not
being created left & right. Does C# have the same problem? I noticed that
C# has a StringBuilder class which is just like the Java StringBuffer class.
Should I use StringBuffer in cases like the above where I need to
concatenate multiple strings to one string?