Given public String(char*) why we cannot use the following statement?
string str = new string("aaa");
Error 1
The best overloaded method match for 'string.String(char*)' has some invalid arguments C:\temp\ConsoleApplication2\ConsoleApplication2\Program.cs 19 26 ConsoleApplication2
Error 2
Argument 1: cannot convert from 'string' to 'char*' C:\temp\ConsoleApplication2\ConsoleApplication2\Program.cs 19 37 ConsoleApplication2
Simply use:
string str = "aaa";
You do not need to new a string.
"aaa" is a string. It is not a char *.
char * is used with unsafe code.
Because this isn't meant to be used in safe code...
In C#, this constructor is defined only in the context of unsafe code.
from: http://msdn.microsoft.com/en-us/library/6y4za026.aspx
If you need to construct a string you could just use the literal decleration..
string str = "aaa";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With