字符串实际上是字符数组还是仅具有索引器? [英] Is string actually an array of chars or does it just have an indexer?
本文介绍了字符串实际上是字符数组还是仅具有索引器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
由于在C#中可能使用以下代码,因此我很怀疑string是否实际上是一个字符数组:
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不是Char的.NET数组,因为:
System.String is not a .NET array of Char because this:
char[] testArray = "test".ToCharArray();
testArray[0] = 'T';
将编译,但这:
string testString = "test";
testString[0] = 'T';
不会.字符数组是可变的,字符串不是.另外,string is Array
返回false,而char[] is Array
返回true.
will not. Char arrays are mutable, Strings are not. Also, string is Array
returns false, while char[] is Array
returns true.
这篇关于字符串实际上是字符数组还是仅具有索引器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文