I know string is a value type in C#. I understand everything in C# are passed by value.
But if it’s a value type anyway there is no need ‘out’ or ‘ref’, right?
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.
String is a reference type (a class) as others have pointed out. It’s just that it’s immutable, which makes it sometimes feel like a value type in some ways.
You can pass a string argument by reference or by value, just as with any other parameter. It’s worth being absolutely clear about the difference between these two concepts. I have two articles on the topic:
It’s worth becoming really familiar with this topic (and reading articles other than mine, of course) – understanding the difference between reference types and value types is absolutely key in C#, and so is understanding parameter passing (and even what a simple assignment statement means).