What is the meaning of "immutable" when relating to an Int32 ?

Int32 i = 0;
i++;
//etc

Recommended Answers

Take a look at this post:

http://stackoverflow.com/questions/575977/choosing-between-immutable-objects-and-structs-for-value-objects

Be sure to read the comments under the second post - goes into a lot of detail concerning your question.

Jump to Post

All 2 Replies

The types are immutable, meaning you can't change their value. 3 = 3 no matter what you want it to be. The variable i in your example isn't immutable, it can be any Int32 value. But as was said, the value itself cannot be changed.

And as was said in the link, generally you use a struct to represent an immutable object. The .Net framework follows this 'rule' (DateTime for example). Methods on the struct return a new struct, they don't modify the one you have.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.