Information Technology Reference
In-Depth Information
Structs As Return Values and Parameters
Structs can be used as return values and parameters.
￿
Return value : When a struct is a return value, a copy is created and returned from the
function member.
￿
Value parameter : When a struct is used as a value parameter, a copy of the actual param-
eter struct is created. The copy is used in the execution of the method.
￿ ref and out parameters : If you use a struct as a ref or out parameter, a reference to the
struct is passed into the method.
Additional Information About Structs
Allocating structs requires less overhead than creating instances of a class, so using structs
instead of classes can sometimes improve performance—but beware of the costs of boxing and
unboxing.
Finally, some last things you should know about structs are the following:
The predefined simple types ( int , short , long , etc.), although considered primitives in
.NET and C#, are all actually implemented in .NET as structs.
￿
￿
Structs, like classes, can implement interfaces.
Search WWH ::




Custom Search