Blog Stats
  • Posts - 16
  • Articles - 0
  • Comments - 24
  • Trackbacks - 1704

 

[70-553] – 1. Section 1 – 1. Dev application – 1 – Manage data (1)

Manage data in a .NET Framework application using .NET Framework 2.0 system types (System namespace)

Value Types:  sono strutture o enumerati e vengono sempre passati per valore. Poichè si parla di “struct” e  non di “puntatori” non possono assumere il valore null. Per l’inizializzazione c’e’ un costruttore di default che permette di assegnare i  default.  E poi ognuno si puo’ creare i propri costruttori in cui assegnare i valori a tutte le variabili membro. Tutti sono derivati implicitamente dalla classe Object.

I tipi di base: integer, double,bool, .. sono value types.

Il riferimento alla teoria è: http://msdn2.microsoft.com/en-us/library/s1ax56ch(VS.71).aspx   ,  facciamo un esempio

public struct PuntoStruct

{

    private double _x, _y,_z;

    //ATTENZIONE

    //public Punto(  ) : non serve !! perchè questo dice la guida!

    //Each struct already has a default constructor that initializes the object to zero.

    //Therefore, the constructors that you can create for a struct must take one or more parameters. 

     public PuntoStruct(double x1, double y1, double z1)

    {

        _x = x1;

        _y = y1;

        _z = z1;                

       //non posso chiamare updateCoords perchè

       //PuntoStruct._x (e _y e _z) must be fully assigned before control leaves the constructor

       //quindi.. non posso delegare ad un'altra funzione.

    }

    public void printPunto(string name)

    {

        Console.WriteLine("{0} x = {1}, y ={2}, z = {3}", name, _x, _y, _z);

    }

    public void updateCoords(double x1, double y1, double z1)

    {

        _x = x1;

        _y = y1;

        _z = z1;            

     }

};

 

 

Lo uso: creo un punto a zero, un punto 1 ed un punto 2 come copia del punto1.  Nelle strutture non c’e’ bisogno di definere l’operatore di copia, ci pensa lui copiando la memoria.  Ora proviamo ad usarla in una console application.

static void Main(string[] args)

{

    PuntoStruct p0 = new PuntoStruct();

    PuntoStruct p1 = new PuntoStruct(10, 20, 30);

    PuntoStruct p2 = p1;

    p0.printPunto("Struct P0: ");

    p1.printPunto("Struct P1: ");

    p2.printPunto("Struct P2: ");

    p1.updateCoords(11, 22, 33);

    p1.printPunto("Struct P1 dopo: ");

    p2.printPunto("Struct P2 dopo: ");

}

 

Il risultato:

       STRUCT PO: x = 0, y = 0; y = 0

       STRUCT P1: x = 10, y = 20; y = 30

       STRUCT P2: x = 10, y = 20; y = 30

       STRUCT P1 dopo: x = 11, y = 22; y = 33

       STRUCT P2 dopo: x = 10, y = 20; y = 30

 

Dopo la modifica di p1, p2 è rimasto invariato, perchè ha un suo spazio di memoria, riempito solo la prima volta dalla copia dei valori di p1, ma poi è rimasto indipendente.

La soluzione con la classe, ed i riferimenti funzioneranno diversamente :-) .

 

 


Feedback

# re: 70-553 – 1. Section 1 – 1. Dev application – 1 – Manage data (1)

Gravatar Io ho trovato molto illuminante la spiegazione dei value type di Jeffrey Richter in CLR via C#. Lo hai già letto? Se no, telo consiglio... ciao Paolo 21/06/2007 22.49 | Paolo

# Alcohol and zoloft.

Gravatar Zoloft. Phentermine zoloft. What is zoloft. Zoloft side effects. 24/04/2008 7.45 | Zoloft dosing.

# Ephedra pills.

Gravatar Denver ephedra attorney. Ephedra is it legal. Ephedra yellow jackets. Ephedra attorneys california. Colorado ephedra attorney. Georgia ephedra attorneys. Ephedra. 25/04/2008 20.39 | Liquid ephedra.

# Meridia and wellbutrin.

Gravatar Meridia. 26/04/2008 21.03 | Does meridia work.

# Disinhibition in adults using zoloft.

Gravatar Zoloft. Taking bupropion hcl and zoloft together. 27/04/2008 8.51 | Zoloft.

# Big boobs.

Gravatar Lanas big boobs. Big boobs. 14/05/2008 15.05 | Big boobs.

# Free blowjob pictures.

Gravatar How to give a blowjob. Gay blowjob. Latina blowjob. Horse blowjob. Free blowjob videos. 27/05/2008 15.55 | Blowjob.

# Torture devices.

Gravatar Breast torture. Bondage torture. Torture. Water torture of women. Male genital torture. Fire torture. Torture porn. 24/01/2009 7.40 | Spanish inquisition torture devices.

# Shag Hairstyles and Haircuts

Gravatar shag hairstyle basically gotits name from the word "shaggy" since ...once the hair is cutand layered it gives off a shaggy look. The shag hairstyle has always been apopular hairstyle, and there are plenty ofshag hairstyles to choose from 26/02/2009 3.24 | shag Haircut and styles

# Swine flu.

Gravatar Swine flu. 1976 swine flu scare. Swine flu shot. Swine flu vaccine. 05/05/2009 11.04 | Swine flu shot.

# Meridia meridia best prices on the net.

Gravatar Book discount guest info meridia number site. Meridia for sale. Meridia. Meridia diet index dietlist net. 06/05/2009 5.28 | Meridia.

# test

Gravatar GqGBwt1 | <a href="http://test.com" >test</a> 21/04/2010 21.46 | http://test.com

Post a comment





 

Please add 8 and 7 and type the answer here:

 

 

Copyright © Bruna Gavioli