#14 Don’t Use StringBuilder EveryWhere

Even though StringBuilder has its Advantage.They have to used Properly.

var FName = Console.ReadLine();
 var LName = Console.ReadLine();
 /*
 * Less Time Consuming and Fast.
 */
 String Name = "FirstName" + FName + "LastName" + LName;
 /*
 * Bad Code,since operation is time consuming though its efficient.
 */</p><p>StringBuilder builder=new StringBuilder();
 builder.Append("FirstName");
 builder.Append(FName);
 builder.Append("LastName");
 builder.Append(LName);</p><p>

1. StringBuilder are ideally suited when you iterate over the string operation for vast number of times.

2.String Concat are better way if you know the literals that have to be concatenated and if they are compile time constant

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s