Whilst this posting is accurate, it does not go a whole long way to explaining the value of value types.
Consider the scenario of a large scale banking system, where system testing suddenly flips a very large number into floating point format (e.g. 1.6e20), and the Java developers say it is major change with performance implications to fix.. a daft statement from a business perspective...
why is it a big changes: because Java does not have a value-type for big decimal numbers (BigDecimal is an object reference type).. and people commonly use double for currency because of the huge overhead (performance and coding) of using java.math.BigDecimal.
struct exists in C# because there are a small number of scenarios where the language would not be appropriate/practical without them {Point (x,y), Complex, Decimal} are common examples of why value types that are essential.. so is there a down-side yes being value-types, they are passed by value (unless the “ref” parameter modifier is used) on the stack.. a Complex number is a good example, a vector of 3000 doubles is a poor example because it is copied every time (unless ref is used).
A cool thing about C# is that you can decide later whether an object needs to be a value-type or not, but judicious use can make an application really fly because values can live of the stack
Enter your message below
Sign in or Join us (it's free).