.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Interview Question >> .NET Framework >> Post New Question Subscribe to Interview Questions

Difference between System.String and System.StringBuilder classes?

Posted By :Maverick     Posted Date :July 31, 2011    Points :40   Category :.NET Framework 
-- System.String is immutable; System.StringBuilder can have mutable string where a variety of operations can be performed.

You can also find related Interview Question to Difference between System.String and System.StringBuilder classes?  below: 

What is difference between System.String and System.StringBuilder classes?

  
String and StringBuilder classes are used to store string values but the difference in them is that String is immutable (read only) by nature, because a value once assigned to a String object cannot be changed after its creation. When the value in the String object is modified, a new object is created, in memory, with a new value assigned to the String object. On the other hand, the StringBuilder class is mutable, as it occupies the same space even if you change the value. The StringBuilder class is more efficient where you have to perform a large amount of string manipulation. (More...)

What's the advantage of using System.Text.StringBuilder over System.String?

  
StringBuilder is more efficient in the cases, where a lot of manipulation is done to the text. Strings are immutable, so each time it's being operated on, a new instance is created. (More...)

Consider the following two classes:

public class Example1
{
public static int num;
static
{
num=5;
}
}


public class Example2
{
public static void main(String[] args)
{
System.out.println(Example1.num);
}
}

Select the correct option regarding the preceding classes.?

  
1, The Example2 class will execute without any output.
2, The Example2 class will execute with the following output:5

3, The Example2 class will not compile as it does not calls the constructor of the Example 1 class.
4, The Example2 class will not execute as it does not calls the constructor of the Example 1 class.

Answer : 2 (More...)

What's the advantage of using System.Text.StringBuilder over System.String?

  
StringBuilder is more efficient in the cases, where a lot of manipulation is done to the text. Strings are immutable, so each time it's being operated on, a new instance is created. (More...)

What's the advantage of using System.Text.StringBuilder over System.String?

  
StringBuilder is more efficient in the cases, where a lot of manipulation is done to the text. Strings are immutable, so each time it's being operated on, a new instance is created. (More...)

What's the advantage of using System.Text.StringBuilder over System.String?

  
StringBuilder is more efficient in cases where there is a large amount of string manipulation. Strings are immutable, so each time a string is changed, a new instance in memory is created. (More...)

What's difference between System.SystemException and System.ApplicationException?

  
The difference between ApplicationException and SystemException is that SystemExceptions are thrown by the CLR, and ApplicationExceptions are thrown by Applications (More...)

What is the difference between "using System.Data;" and directly adding the reference from "Add References Dialog Box"?

  
When you compiles a program using command line, u add the references using /r switch. When you compile a program using Visual Studio, it adds those references to our assembly, which are added using "Add Reference" dialog box. While "using" statement facilitates us to use classes without using their fully qualified names.

For example: if u have added a reference to "System.Data.SqlClient" using "Add Reference" dialog box then u can use SqlConnection class like this:

System.Data.SqlClient.SqlConnection

But if u add a "using System.Data.SqlClient" statement at the start of ur code then u can directly use SqlConnection class.

On the other hand if u add a reference using "using System.Data.SqlClient" statement, but don't add it using "Add Reference" dialog box, Visual Studio will give error message while we compile the program. (More...)

What's the difference between the System.Array.CopyTo() and System.Array.Clone() in c#?

  
The first one performs a deep copy of the array, the second one is shallow. (More...)

What's the difference between the System.Array.CopyTo() and System.Array.Clone()?

  
The Clone() method returns a new array (a shallow copy) object containing all the elements in the original array. The CopyTo() method copies the elements into another existing array. Both perform a shallow copy. A shallow copy means the contents (each array element) contains references to the same object as the elements in the original array. A deep copy (which neither of these methods performs) would create a new instance of each element's object, resulting in a different, yet identacle object. (More...)

Name the classes that are contained in System.Data NameSpace?

  
DataSet
DataTable
DataColumn
DataRow
DataRealation
Constraint (More...)

What is difference between System.Web.Caching.Cache and System.Web.HttpContext.Current.Cache ?

  
System.Web.Caching.Cache : Class/type used for caching
System.Web.HttoContect.Current.Cache : The instance of cache class for current HTTP context from a web request (Gets cache object from current application domain) (More...)

difference between string and StringBuilder?

  
String is immutable & StringBuilder is mutable.
Means we can add, remove or append the words in stringbuilder but not in string. And stringbuilder have larger range of storing than string. (More...)

Quick Links For Interview Questions Categories:
ASP.Net Windows Application   .NET Framework   C#   VB.Net   ADO.Net  
Sql Server   SharePoint   Silverlight   OOPs   JQuery   JavaScript/VBScript
Biztalk Patten/Practices .IIS WCF WPF WWF
Networking Aptitude Others   All      

Find questions, FAQ's and their answers related to .NET, C#, Vb.Net, Sql Server and many more.

 
Now you can find lots of .NET, C#, Vb.Net, SQL Server,Windows, ASP.Net related Questions and their Answers here at www.dotnetspark.com. Our aim is to help you pass your certification Exams (MCP, MCSD, MCAD etc.,) with flying scores and get good name in your company.

So, Start looking our Interview Question section daily and improve your .NET Skills. You can also help others by posting Interview Questions and their Answers in this section.


Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend