Cannot take the address of the given expression C# pointer

前端 未结 3 1846
一整个雨季
一整个雨季 2021-01-06 01:45

Consider the following code in an unsafe context:

string mySentence = \"Pointers in C#\";

fixed (char* start = mySentence) // this is the line we\'re talkin         


        
3条回答
  •  时光说笑
    2021-01-06 02:11

    mySentence[0] returns a readonly single character, you cannot get a pointer to that.

    Use:

    fixed(char* start = &mySentence)
    

    instead.

提交回复
热议问题