Programming tip of the day – Mutable and Immutable

Immutable -> Once a variable has been assigned its value, value cannot be modified in the same memory location.  It allocates a new memory space and then puts the modified contents into that variable.

Mutable -> Variable’s value can be modified in the same memory location.


Eg.  String in C# and VB.NET is immutable, StringBuilder is mutable.

String cont = “1”;

cont = cont + ” 2″; //Allocates new memory and adds value ” 2″ inside it

StringBuilder builder = new StringBuilder(“1″);

builder.add(” 2″); //Modifies the value in the same location.


 Moral: For strings that require constant change/modification, use StringBuilder (C#) for better performance.

Contact Form

By clicking 'Submit' you Agree to Guvi Terms & Conditions.

Our Learners Work at

Our Popular Course

Share this post

Author Bio


Our Live Classes

Learn Javascript, HTML, CSS, Java, Data Structure, MongoDB & more
Learn Python, Machine Learning, NLP, Tableau, PowerBI & more
Learn Selenium, Python, Java, Jenkins, Jmeter, API Testing & more
Learn Networking, Security Testing, IAM, Access Management & more

Hey wait, Don’t miss New Updates from GUVI!

Get Your Course Now

Related Articles