0

I am little confuse about string. I know it's reference type but when i tried, it shows the behavior of value type. I tried this:

String a = "abc";

String b = a;

b="xyz";

//When i print both a and b

a is abc
b is xyz

I was expecting both a and b print as xyz. Because they are reference type. After that, i made a function

public static void change(string a)
{
    a="hello";
}
//In main i did this.

String a="abc";

Change(a);

I thought a will print as "hello" because it is refrence type but it still shows abc. If it is refrence type then why it behave like valu type?

CodeLover
  • 271
  • 1
  • 3
  • 14

0 Answers0