C#C
C#9mo ago
yourFriend

In String constructor `String(Char*)`, `Char*` is character pointer or character array pointer?

I was exploring
System.String
class here: https://learn.microsoft.com/en-us/dotnet/api/system.string?view=net-9.0

And one of the constructors is
String(Char*)


Its description says: Initializes a new instance of the String class to the value indicated by a specified pointer to an array of Unicode characters.

However, I got error, when I tried following code to initialize string using pointer to an array of characters:
char[] cArray = {'a','r','r','a','y'};
char[]* cArray_ptr = &cArray;
string s = new string(cArray_ptr); // Error: cannot convert char[]* to char*


So, my question is:
  1. Is
    String(Char*)
    takes character pointer as argument instead of character array pointer?
  2. Or am I doing some mistake in declaring and initializing character array pointer?
Screenshot_485.png
Screenshot_486.png
Represents text as a sequence of UTF-16 code units.
Was this page helpful?