本文介绍了如果string是引用类型,如何将其值从另一个对象更改为数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

string是一个引用类型,如何将其值从另一个对象更改为数组,例如



数组:

string is a reference type,How can I change its value from another object as array for example

Array:

var numbers = new int[] {1,2,3};
var numbers2 = numbers;
numbers2[0] = 9;
Console.WriteLine(numbers[0]); //Output is:9 because arrays is a rference type





我尝试过:



字符串:



What I have tried:

String:

var numbers = new string(new char[]{'o','n','e'});
var numbers2 = numbers;
numbers2 = "two";
Console.WriteLine(numbers); //why the output here is "one" it should be "two" it is a reference type??!!

推荐答案


这篇关于如果string是引用类型,如何将其值从另一个对象更改为数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 22:55