Using the .NET Framework, developers can both define and share types. Defining and sharing new types in a single language is not particularly challenging; allowing a newly defined type to be used in other languages is much more problematic. This type system will help developers to achieve the concepts of interoperability.


 


Elements of the CLR Type System









Value Type:


A value type consists of a sequence of bits in memory, such as a 32-bit integer. Any two 32-bit integers are considered equal if they hold the same number—that is, if the sequence of bits is identical. Value types represent types that are known as simple or primitive types in many languages. They include types such as int and float in C++ and Java. Value types are often allocated on the stack, which means that they can be local variables, parameters, or return values from functions.


 


The following Types comes under the value type:-


 


1. Boolean Values :-The bool type is used to represent true and false values. Unlike some languages that use an integer for this type (so that a value such as 0 represents false and all other values represent true), the CLR designates a specific type for this purpose.


CIL Name: bool


Base Framework Name: System.Boolean


 


2.Characters :- All characters in the CLR are 16-bit Unicode code points . The UTF-16 character set uses 16 bits to represent characters; by comparison, the ASCII character set normally uses 8 bits for this purpose. This point is important for a component model such as the .NET Framework, for which distributed programming over the Internet was a prime design goal of the architecture.


 


3. Integers :-The CLR supports a range of built-in integer representations. Integers vary in three ways:



  • Their size can be 8, 16, 32, or 64 bits. This range covers the size of integers in many common languages and machine architectures.

  • Integers can be signed or unsigned, designating whether the values they hold are positive only or positive/negative.

  • Native integers are used to represent the most natural size integer on the execution architecture. Because the CLR is designed to run on a number of different platforms, it needs a mechanism to inform the execution engine that it is free to choose the most efficient representation on the platform that the code executes on—hence the native integer type.


4] Floating-point Types: - CLR floating-point types vary between 32- and 64-bit representations and adhere to the IEEE floating-point standard


 


5] User-Defined Value Types: -The following are the User-Defined Types in .Net



  • Enumerations: :-An enumeration is a special kind of value type limited to a restricted and unchangeable set of numerical values.Enums are strongly typed constants. They are essentially unique types that allow you to assign symbolic names to integral values. Example:-
    using System;
    namespace Enumeration {
    struct EnumerationSample {
    enum Month {
    January = 1, February,
    March, April,
    May, June,
    July, August,
    September, October,
    November, December}

    static int Main (string[] args) {
    Console.WriteLine("{0} is month {1}", Month.September,(int) Month.September); return 0;
    }
    }
    }



  • Structure: -Some languages, such as Managed C++, allow users to use a keyword such as classwhen defining either value or reference types. Other languages, such as C#, use a keyword such as struct to indicate a user-defined value type and class to indicate a user-defined reference type. Structures can contain Methods (both static and instance), Fields (both static and instance) , Properties (both static and instance) and  Events (both static and instance).


 


 


 

                    

Dotnet Related Tutorials

...more

New Dotnet Resources

...more

Copyright © 2010 VisualBuilder. All rights reserved