(This articles is purely meant for beginners in .Net) Introduction Structures are user defined value types. In this article we will discuss various features of structures which .net framework provides. As a programmer, we all must have heard about type. What is a type ? Types represent a combination of behavior and data storage requirements. When our program runs, it creates instances of types(which allocates the data storage required) and makes the behavior of the types available to us.
For each type, the complier knows How much memory to allocate when we create a value of this type and also what operations we are allowed to perform using the value. The .Net framework defines the common language specification (CLS) to facilitate seamless language interoperability. Common Type System (CTS) is responsible for all the languages in .Net Framework to interoperate smoothly. CTS specifies how to declare new types, how to create instances of these types, and how the CLR manages the lifetimes of these instances. Basically, CTS categorizes the types into three divisions
- Interfaces
- Value Types
- Reference Types
Now, I am interested only in the Value Types, Lets have a close look at the value types and proceed with the Structures. Value Types. Value types represent entities that are essentially numerical in nature, such as the date and time, colors, etc. Such entities can be represented by simple binary number of a fixed length – the only complication is in interpreting the meaning of the number. Further, Value Type are composed of three main categories, they are
- Primitive Types
All the programming languages define primitive types such as integers, floating point numbers, and so on. - User Defined Value types
Structures are user defined value types. - Enumerations
An enumeration is a special kind of user-defined value type ( We will see more about Enumeration in my upcoming article "How Enumerations can be used in .Net".
Structures Why is it required? Say, for example we want to store a information of a student ie., rollno, student name, class, section etc., This can be achieved in three different ways Declaring them separately, Disadvantages in this approach ,
- When variables are declared in this fashion, we cannot
handle them as a single entity. - And If we want to handle more than one student record, we need to declare
that many no of variable and do our process.
Declaring them as a Class This is also very good approach, It brings all of them into one type, but the disadvantage of this approach is the run-time overhead of garbage-collecting these simple objects would be unnecessarily high. Best approach is using a Structure.
See all the Structure in VB.Net Part 1, Part II , Part III,Part IV,Part V Please send your valuable feed back to sadhasivam1981@yahoo.com.
Visit http://sadhasivam.t35.com to know more about me.
|
No responses found. Be the first to respond and make money from revenue sharing program.
|