User FAQs
If you have a question, please send it to us.
1) What is the difference between System.String and System.Text.StringBuilder ?
System.Text.StringBuilder is not an immutable data type and is therefore more efficient when a lot of string manipulations are required.
System.String is an immutable data type.
System.Text.StringBuilder myStringBuilder;
myStringBuilder = new System.Text.StringBuilder("some text");
myStringBuilder.Append("more");
myStringBuilder.Replace("e","a");
2) Can you give an example of string interpolation ?
Use string interpolation to concatenate short strings, as shown in the following code.
string displayName = $"{nameList[n].LastName}, {nameList[n].FirstName}";
3) What is the fastest way to append strings in a loop ?
To append strings in loops, especially when you're working with large amounts of text, use a StringBuilder object.
var phrase = "la";
var manyPhrases = new StringBuilder();
for (var i = 0; i < 10000; i++)
{
manyPhrases.Append(phrase);
}
4) What does the @ prefix mean at the start of a text string ?
When you use a "@" prefix you do not have to escape any special characters.
For example you do not have to use a double slash \\ when you want to include a slash.
However you do have to use two double quotes to input a double quote.
string myString = "C:\\temp"
string myString = @"C:\temp"
string myString = @"You need a double quote "" for a double quote"
© 2023 Better Solutions Limited. All Rights Reserved. © 2023 Better Solutions Limited TopPrevNext