Is string reference type / value type?

Answer Posted / djfox7200x

Strings are immutable.Hence they behave like a value type
when they are actually reference type;

eg. string objA="cat";
//cat is an immutable string in memory and objA points to
it.
string b=a; //reference is copied to b;

a="dog"; new immutable object created and a points to it;

//b is still cat since its refernce has not changed

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is typeof c#?

540


How many types of delegates are there in c#?

466


Can an array be null c#?

504


What is the difference between dll and lib?

479


what is c# command?

503






How can you achieve run time polymorphism in C#?

545


How big is an int16?

494


Should I use double or float?

502


What is the difference between int and int in c#?

495


What framework is used for performance testing/load testing?

1482


Is datetime nullable c#?

506


What is object pool in .net?

534


Which language is used for desktop application?

486


What exactly is serverless?

425


What is class method?

474