Value types behavior shows that whatever value we are holding cannot be changed through some other variable .
But I still have a confusion in my mind about what i mentioned in the title of this post . Can anyone clarify?
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.
Value types can be either mutable or (modulo some weird edge cases) immutable, depending on how you write them.
Mutable:
Immutable:
The built-in value types (
int,doubleand the like) are immutable, but you can very easily create your own mutablestructs.One piece of advice: don’t. Mutable value types are a bad idea, and should be avoided. For example, what does this code do:
It depends. If
SomeTypeis a value type, it prints5, which is a pretty confusing result.See this question for more info on why you should avoid mutable value types.