C#不变引用类型-字符串

示例

// 从字符串文字中分配字符串
string s = "hello";

// 从字符数组分配字符串
char[] chars = new char[] { 'h', 'e', 'l', 'l', 'o' };
string s = new string(chars, 0, chars.Length);

// 从字符串派生的char指针分配字符串
string s;
unsafe
{
    fixed (char* charPointer = "hello")
    {
        s = new string(charPointer);
    }
}