Click here to Skip to main content
16,012,061 members
Please Sign up or sign in to vote.
1.31/5 (4 votes)
See more:
what is difference between
C#
String s = "Test";

String s = new String("Test");
Posted
Updated 28-May-14 4:17am
v2
Comments
[no name] 28-May-14 10:18am    
The difference is the first line will compile and the second will not as creating a string with a string makes no sense.
ZurdoDev 28-May-14 10:28am    
Did you even try it?

C#
  String s = "Test";
  //This Will Set value "Test" into string variable

   String sData = new String("Test");
   //This will give an error like this..
//The best overloaded method match for 'string.String(char*)' has some invalid arguments
 
Share this answer
 
v2
The difference is that the first does compile, but the second does not. It gives this error:
Quote:
The best overloaded method match for 'string.String(char*)' has some invalid arguments

Why? Because the constructor of String does not take a string as argument. You can find an overload list here:
http://msdn.microsoft.com/en-us/library/system.string.string.aspx[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900