Value Types and Passing Method Params by Ref in Visual J# .NET 2005

A value type is similar to a class in that both represent an aggregate that can contain data members and function members. However there are a few key differences:

(1) unlike classes, instances of value types do not require heap allocation

(2) a variable of a value type directly contains the data of the type, whereas a variable of a class type contains a reference to the data (the object).

(3) the semantics of '==' are different

(4) casting from/to a valuetype does boxing/unboxing as appropriate automatically

(5) they cannot be compared to or assigned 'null'.

Value Types make it possible to author “Light weight classes”. This enables scenarios where developers want to use objects similar to primitive types, briefly and in a single location, and do not want the overhead of such objects hanging around and wait for garbage collection thus adding overhead to the program. Value types typically are a complete abstraction and are not meant to be extended. As a result, methods on a valuetype do not incur the overhead of dynamic dispatch. These would be really useful to represent complex numbers, points, transforms, ranges, etc. - these are abstractions that support value semantics. You may want to read in detail about value types here -

Support for passing parameters by reference in Visual J# .NET 2005 enables higher performance when passing valuetypes. Typically when passing a value type to a method the entire aggregate is copied. Note that in this case the parameter can be modified inside the method and these changes are visible to the caller immediately. - passing parameters by reference provides aliasing semantics. Again this is a powerful feature and opens up several new scenarios where J# can be applied. You may read in detail about passing parameters by reference in detail here -

Skip to main content