What is the logic/reason behind making
String s= new String("Hello World");
Illegal in C#? The error is
The best overloaded method match for `string.String(char*)' has some invalid arguments
I'm not interested in the API docs, I am interested in why this is illegal.
Is is because of pooling static strings? like Java pools Integer(-128) to Integer(127) with horrendous results? ( of course strings too )
You can use " \\ " instead of " \ " as well as '@' sign in the beginning.
Why should you use immutable strings? One advantage is that they are thread safe. If you are working with a multi threaded system, there will be no risk of a deadlock or any concurrency issues, since when you modify a string, you are really just creating a new object in memory.
A string is an object of type String whose value is text. Internally, the text is stored as a sequential read-only collection of Char objects. There's no null-terminating character at the end of a C# string; therefore a C# string can contain any number of embedded null characters ('\0').
It would be rather pointless to use the constructor to create a new string based on another existing string - that's why there is no constructor overload that allows this. Just do
string s = "Hello World";
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