Monday, 6 February 2017

DIFFERENCE BETWEEN SYSTEM.STRING AND SYSTEM.TEXT.STRINGBUILDER

DIFFERENCE BETWEEN SYSTEM.STRING AND SYSTEM.TEXT.STRINGBUILDER


System.String is immutable  |||      StringBuilder is Mutable

As StringBuilder objects are mutable, they offer better performance than string objects of type
System.String, when heavy string manipulation is involved.



EXAMPLE OF SYSTEM.STRING  I.E STRING() METHOD
Stack       and       Heap
string                   c#
                            vidoe
                             tutorial
                             for
                             beginners


EXAMPLE  OF SYSTEM.TEXT.STRINGBUILDER
Stack       and       Heap
string                   c# video tutorial for beginners


using System;
using System.Text;
namespace ConsoleApplication4
{
    public class MainClass
    {
        public static void Main()
        {


            string userString = string.Empty;
            for(int i = 1; i <= 10000;i++ )
            {
                userString += i.ToString() + " ";
                
            }
            Console.WriteLine(userString);
            Console.ReadLine();
            
            // using system.string  
            //string userstring = "C#";
            //userstring += "Vidoe";
            //userstring += "Tutorail";
            //userstring += "for";
            //userstring += "Beginners";
            //Console.WriteLine(userString);
            //Console.ReadLine();


            //// using system.text.stringbuilder
            //StringBuilder userString = new StringBuilder("C#");
            //userString.Append(" Video");
            //userString.Append(" Tutorial");
            //userString.Append(" For");
            //userString.Append(" Beginners");
            //Console.WriteLine(userString.ToString());
            //Console.ReadLine();

        }

    }

}

   

No comments:

Post a Comment

Note: only a member of this blog may post a comment.