Tuesday, December 3, 2013

STRING AND STRING BUILDER

STRING AND STRING BUILDER  (C#)

Introduction

               The string and stringbuilder in c# using asp.net and their differences.

Description

          In my previous posts we have seen Oops conceptsSql Data ReaderAdo Objects  here we going to see about the string and stringbuilder and their difference.

String

          The string is a data type object which replaces its value if we use insert, update or append. That means each time it will create a separate memory space for its value in the memory to hold a new value.

Example:

StringBuilder 

             In the stringbuilder the insert, update and append can be performed with the first instance without creating   instance each time.

Example:

                 
Difference between string and stringbuilder 

String
1. Low performance than stringbuilder as it creates instance on every instance.   
2. In string it uses "+"  operator for append.
3. String requires System namespace.

Stringbuilder
1. High performance than string as it doesn't creates instance on every instance.   
2. In stringbuilder it uses append for adding.
3. String requires System.Text namespace.


Normally for small usages we use string
The string builder can be used for the special cases like, when we press print button on the ticket page the response page will be as per the given input that type of requirement we use stringbuilder.

******************************************************

No comments:

Post a Comment