Wednesday, March 24, 2010

Structs vs. Classes

The word “struct” originally an abbreviation of structure, has become a part of the programming terminology of structure, has become a part of the programming terminology. In C#, the struct is a user – defined value type. It might, however, contain members of both reference types and value types.
The struct is used to represent lightweight objects such as a point, which contains two fields( x and y). It also represent a color, which contains three fields (red, blue, and green). Although we use the Point class in the examples, the struct is a more suitable type for such objects as it consumes a small amount of memory. We can see the difference if we create a large array of points represented as classes. In this case, the required memory would be huge because each point is using a reference that points to it.

No comments:

Post a Comment