Home Tutoriels C# /.net C# - Value Types

C# - Value Types

Envoyer Imprimer
Hits smaller text tool iconmedium text tool iconlarger text tool icon
  • Introduction to C# and Microsoft .NET Framework
    C# (pronounced "see sharp") is a multi-paradigm programming language encompassing imperative, functional, generic, object-oriented (class-based), and component-oriented programming disciplines. It was developed by Microsoft within the .NET initiative and later approved as a standard by Ecma (ECMA-334) and ISO (ISO/IEC 23270). C# is one of the programming languages designed for the Common Language Infrastructure.
    C# is intended to be a simple, modern, general-purpose, object-oriented programming language.[3] Its development team is led by Anders Hejlsberg, the designer of Borland's Turbo Pascal, who has said that its object-oriented syntax is based on C++ and other languages. James Gosling, who created the Java programming language in 1994, called it an 'imitation' of that language. The most recent version is C# 3.0, which was released in conjunction with the .NET Framework 3.5 in 2007. The next proposed version, 4.0, is in development.


    The Microsoft .NET Framework is a software framework that can be installed on computers running Microsoft Windows operating systems. It includes a large library of coded solutions to common programming problems and a virtual machine that manages the execution of programs written specifically for the framework. The .NET Framework is a Microsoft offering and is intended to be used by most new applications created for the Windows platform.




  • Value Types
    The .NET framework includes a large number of built-in types that you can use directly or use to build your own custom types.
    The Value types directly contain their data offering excellent performance. However, value types that store very small pieces of data. In the .NET framework, all value types are 16 bytes or shorter. You can create user-defined types that store multiple values and methods.
    In object-oriented developement environements, a large portion of your application logic will be stored in user-defined types.
    We can also use Enumerations to improve code readability by providing symbols for a set of values.
    • Instances of value types are stored in an area of memory called the stack, where the runtime can create, read, update, and remove them quickly with minimal overhead
    • General value types: Built-in types - User-defined - types Enumerations
    • There are nearly 300 value types in the framework.
    • Even though value types often represent simple values, they still function as objects
    • All types are derived from System.Object


Declaration of Value Types
  • Value types have an implicit constructor. The constructor assigns a default value (usually null or 0) to the new instance.
  • Default Values Table
    C# Type .NET Framework Type CLS-Compliant Description
    byte System.Byte Yes 8 bit unsigned integer
    sbyte System.SByte No 8 bit signed integer
    short System.Int16 Yes 16 bit signed integer
    ushort System.UInt16 No 16 bit unsigned integer
    int System.Int32 Yes 32 bit signed integer
    uint System.UInt32 No 32 bit unsigned integer
    long System.Int64 Yes 64 bit signed integer
    ulong System.UInt64 No 64 bit unsigned integer
    float System.Single Yes 32 bit; IEEE comform Floating-Point-Value
    double System.Double Yes 64 bit; IEEE comform Floating-Point-Value
    decimal System.Decimal Yes 128 bit Floating-Point-Value
    (1 bit sign; 96 bit value; 8 bit exponent; 23 bit unused)
  • We should explicitly initialize the variable within declaration

    //C# code
    bool b = false;
  • We can declare the variable as nullable. (Example: Yes/No question)
Nullablew<bool> b = null;
//shorthand notation, only for C#
bool? b= null;

//For this example, we can test if the user has answered to our Yes or No question
if(b.HasValue)
Console.WriteLine("b is {0}.",b.Value);
else
Console.WriteLine("b is not set.");
  • User-Defined Types
    Structures or simply structs In most other ways, structures behave nearly identical to classes.
    Example:
    struct Cycle
    {
    //Private fields
    int _val,_min,_max;
    //constructor
    public Cycle(int min, int max)
    {
    _val = min;
    _min = min;
    _max = max;
    }
    public int value
    {
    get { return _val}
    set{
    if(value > _max || value < _min)
    _val = _min;
    }
    }
    public override string ToString()
    {
    return Value.ToString();
    }

    //operators
    public static Cycle operator+(Cycle arg1, int arg2)
    {
    arg1.value += arg2;
    return arg1;
    }
    }

    We should define a structure rather than a class, if the type will perform better as a value type than a reference type
    Logically represents a single value Has an instance size less than 16 bytes Will not be changed after creation Will not be cast to a reference type.

  • Enumerations
    enum Titles : int{Mr,Mme, Dr};
    Titles t = Titles.Dr;

    The pupose of enumerations is to simplify coding and improve code readability.
Commentaires
Ajouter un nouveau
Cheap Designer Handbags Sale (218.6.26.xxx) 2010-03-11 06:30:23

Save up to 75% with handbags on sale at bagmalls.com.Fashion handbags shop offering a great selection of stylish discount handbags including Jimmy Choo Handbags Discount,Miumiu Handbags Sale,Dior Handbags Wholesale,and stylish discount handbags.you can purchase online.

CHI Hair straighteners (218.6.26.xxx) 2010-03-11 06:29:30

Whatever your hair type is, CHI Flat Iron creates the look you want.Buy the cheapest CHI Hair straighteners protects,CHI Straightener Black your hair while styling. Enjoy free shipping.

cheap uggs
uggs on sale (117.26.227.xxx) 2010-03-10 14:07:37

UGG Boots is the world's premier brand of authentic UGG sheepskin footwear and remains the leader in quality, innovation and style, we offer you the most popular and fashion Uggs such as Ugg Bailey Button , Ugg Classic Tall, Ugg Classic Cardy and so on . Ugg Boots on Sale with Fast delivery!And free shipping!

cheap uggs
uggs on sale (117.26.227.xxx) 2010-03-10 13:42:57

UGG Boots is the world's premier brand of authentic UGG sheepskin footwear and remains the leader in quality, innovation and style, we offer you the most popular and fashion Uggs such as Ugg Bailey Button , Ugg Classic Tall, Ugg Classic Cardy and so on . Ugg Boots on Sale with Fast delivery!And free shipping!

http://www.dropshippingwatch.com/
replica handbags (222.222.251.xxx) 2010-01-07 02:44:03

Rolex Daytona Chronograph Automatic Dark Blue Dial with Rome Marking
Rolex Daytona Chronograph Automatic Gold Case with White Dial
Rolex Daytona Chronograph Automatic with White Dial
Rolex Daytona Chronograph Automatic Full Gold with White Dial


http://www.dropshippingwatch.com/
replica handbags (222.222.251.xxx) 2010-01-07 02:32:59

Rolex Daytona Chronograph Automatic with Diamond Bezel-Blue Dial
Rolex Daytona Chronograph Automatic Diamond Bezel with Green Dial a...
Rolex Daytona Chronograph Automatic PVD Case and Strap with Black D...
Rolex Daytona Chronograph Automatic Full Gold with Black Dial
Rolex Daytona Chronograph Automatic Diamond Bezel with Yellow Dial ...


http://www.dropshippingwatch.com/
replica handbags (222.222.251.xxx) 2010-01-07 02:19:57

Rolex Day-Date Automatic Diamond Marking with Black Dial
Rolex Day-Date Automatic Two Tone with White Dial
Rolex Day-Date Automatic with Blue Dial-Roman Marking
Rolex Day-Date Automatic Diamond Bezel and Marking with Black Dial
Rolex Day-Date Automatic Full Gold with White Dial
Rolex Day-Date Automatic with White Dial


http://www.dropshippingwatch.com/
replica handbags (222.222.251.xxx) 2010-01-07 02:00:51

Rolex Day-Date Automatic Diamond Bezel and Dial with Green
Rolex Day-Date Automatic Diamond Marking with Black Computer Dial
Rolex Day-Date Automatic Full Gold with Diamond Bezel and Marking--...
Rolex Day-Date Automatic Full Gold with Diamond Bezel and Marking--...
Rolex Day-Date Automatic Full Gold with Silver Dial
Rolex Day-Date Automatic Diamond Bezel and Marking with Computer Dial


http://www.dropshippingwatch.com/
replica handbags (222.222.251.xxx) 2010-01-06 15:35:31

Rolex DateJust Swiss ETA 2836 Movement Full Gold with Golden Dial
Rolex DateJust Turn-O-Graph Swiss ETA 2836 Movement with White Dial
Rolex DateJust Turn-O-Graph Swiss ETA 2836 Movement with Black Dial
Rolex DateJust Swiss ETA 2836 Movement with Black Dial-Roman Marking
Rolex DateJust Swiss ETA 2836 Movement Two Tone with Golden Dial
Rolex DateJust Swiss ETA 2836 Movement with 14K Wrapped Gold-Two To...


http://www.dropshippingwatch.com/
replica handbags (222.222.251.xxx) 2010-01-06 14:14:49

Rolex DateJust Automatic with Blue Dial New Version
Rolex DateJust Automatic Diamond Marking with White Dial
Rolex DateJust Turn-O-Graph Automatic with Blue Dial
Rolex DateJust Automatic Two Tone with Golden Dial-Roman Marking


http://www.dropshippingwatch.com/
replica handbags (222.222.251.xxx) 2010-01-06 13:55:40

Rolex Masterpiece Automatic Full Gold Diamond Bezel and Marking wit...
Rolex Masterpiece Automatic Three Tone with Diamond Marking-Blue Dial
Rolex Masterpiece Automatic Full Gold Diamond Markings and Bezel wi...
Rolex Masterpiece Automatic Full Gold with Diamond Dial-Roman Marking
Rolex Masterpiece Automatic Full Gold with Blue MOP Dial-Roman Mark...


http://www.dropshippingwatch.com/
replica handbags (222.222.251.xxx) 2010-01-06 13:49:33

Rolex Masterpiece Automatic Diamond Marking with Blue Computer Dial
Rolex Masterpiece Automatic Two Tone with Diamond Marking-Champagne...
Rolex Masterpiece Automatic Diamond Bezel and Marking with Black Co...
Rolex Masterpiece Automatic Three Tone with White Dial
Rolex Masterpiece Automatic Diamond Bezel and Marking with Blue Com...


http://www.dropshippingwatch.com/
replica handbags (222.222.251.xxx) 2010-01-06 13:36:11

Rolex Milgauss Swiss ETA 2836 Movement with White Dial Vintage Edition
Rolex Milgauss Swiss ETA 2836 Movement with Black Dial
Rolex Milgauss Swiss ETA 2836 Movement with White Dial
Rolex Milgauss Swiss ETA 2836 Movement with Black Dial
Rolex Milgauss Swiss ETA 2836 Movement with Black Dial
Rolex Milgauss Swiss ETA 2836 Movement with White Dial
Rolex Milgauss Swiss ETA 2836 Movement with Black Dial Vintage Edition


http://www.dropshippingwatch.com/
replica handbags (222.222.251.xxx) 2010-01-06 08:43:56

Rolex Day-Date Swiss ETA 2836 Movement Full 18K Gold with Full Diam...
Rolex Day-Date Swiss ETA 2836 Movement Full 18K Gold with Full Diam...
Rolex Day-Date Swiss ETA 2836 Movement Full Gold with Full Diamond
Rolex Day-Date Swiss ETA 2836 Movement with Full Diamond Dial-Updat...
Rolex Datejust Automatic Full Gold Diamond Marking with Golden Comp...
Rolex Datejust Automatic with White Dial








Ecrire un commentaire
Nom :
Email :
 
Website :
Titre :
BBCode :
[b] [i] [u] [url] [quote] [code] [img] 
 
:angry::0:confused::cheer:B):evil::silly::dry::lol::kiss::D:pinch::(
:shock::X:side::):P:unsure::woohoo::huh::whistle:;):s
Saisissez le code que vous voyez.
Mis à jour ( Dimanche, 15 Novembre 2009 15:29 )  

Authentification


Annonces

Info Plus en Facebook

Info Plus on Facebook

Nuages de Tags