C# - 是字符串实际上字符数组或者它只是有一个索引? [英] C# - is string actually an array of chars or does it just have an indexer?
本文介绍了C# - 是字符串实际上字符数组或者它只是有一个索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如下面的代码可以在C#中,我位数的字符串是否实际上是字符数组:
字符串=TEST;
字符C = A [0]; //将被T
解决方案
System.String不是字符的.NET数组,因为这样的:
的char [] = testArray测试.ToCharArray();
testArray [0] ='T';
将编译,但是这样的:
字符串的TestString =测试;
的TestString [0] ='T';
不会。字符数组是可变的,字符串都没有。此外,字符串数组
返回false,而的char []是阵列
返回true。
As the following code is possible in C#, I am intersted whether string is actually an array of chars:
string a="TEST";
char C=a[0]; // will be T
解决方案
System.String is not a .NET array of Char because this:
char[] testArray = "test".ToCharArray();
testArray[0] = 'T';
will compile, but this:
string testString = "test";
testString[0] = 'T';
will not. Char arrays are mutable, Strings are not. Also, string is Array
returns false, while char[] is Array
returns true.
这篇关于C# - 是字符串实际上字符数组或者它只是有一个索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文