String is not value type, but we still use it like it’s value type. So, is string s; compiled to something like string s = new String(..);?
String is not value type, but we still use it like it’s value type.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
When you define
string s;you only define a reference, which currently points to nothing at all. As string is a reference type, the compiler will not generatestring s = new String(..);. You may understand it asstring s = null;will be the compilation result.For value types, such as int, the case is different. For example, when you define
int i;, it will compile toint i = 0;where 0 is the default value.