Why is new String(“Hello”) invalid in C#?

后端 未结 9 2496
太阳男子
太阳男子 2021-02-19 03:41

What is the logic/reason behind making

String s= new String(\"Hello World\");

Illegal in C#? The error is

The best over

9条回答
  •  忘了有多久
    2021-02-19 04:45

    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";
    

提交回复
热议问题