Hahaha

282 mots 2 pages
Les structures :
Permet de créer un type contenant plusieurs types
Syntaxe : struct NomStructure
{
Déclaration des variables…
}
La structure est un type valeur
L’instanciation se fait comme avec n’importe quel type.
On peut utiliser une structure à l’intérieur d’une structure
L’utilisation de chacun des éléments de la structure se fait en donnant le nom de la variable de type structure suivi d’un point et de son élément. S’il y a plus d’un niveau, un point sépare chacun des niveaux.
Les tableaux d’une structure ne peuvent pas avoir une longueur initiale. Il faut donc les dimensionner après l’instanciation de la variable structure.

Le programme exemple sur les structures :

using System;

class Module1
{
// ***** les structures ***** // déclaration du type structure Exemple1 struct sExemple1 { public int Var1; public int[] Tableau; } // fin Structure sExemple1 //déclaration du type Exemple2 struct sExemple2 { public sExemple1 Struc1; public int unNombre; } // fin structure sExemple2

// ****main **** static void Main() { int i; int j; int[] TableauOriginal = new int[4] {1,2,3,4}; //instanciation d'une variable de type structure Exemple1 sExemple1 UnExemple;

//Dimentionner le tableau de la variable UnExemple UnExemple.Tableau = new int[4];

//Mettre des valeurs dans la variable UnExemple.Var1 = 5; UnExemple.Tableau[0] = 10; UnExemple.Tableau[1] = 11; UnExemple.Tableau[2] = 12; UnExemple.Tableau[3] = 13;

//copier le tableau de la structure dans TableauOriginal, à partir de l'indice 0 //et modifier ensuite UnExemple.Tableau(3) UnExemple.Tableau.CopyTo(TableauOriginal, 0); UnExemple.Tableau[3] = 14;

Console.WriteLine("TableauOriginal[3] = " + TableauOriginal[3]);

en relation

  • Hahahahaha
    484 mots | 2 pages
  • haha
    1242 mots | 5 pages
  • Haha
    663 mots | 3 pages
  • Hahaha
    1198 mots | 5 pages
  • Ahahahahaha
    812 mots | 4 pages
  • Math
    949 mots | 4 pages
  • Haha
    1097 mots | 5 pages
  • Haha
    713 mots | 3 pages
  • Devoir maison n°6-corrigé
    666 mots | 3 pages
  • Haha
    1233 mots | 5 pages
  • Hahahah
    501 mots | 3 pages
  • Haha
    352 mots | 2 pages
  • Hahahaha
    555 mots | 3 pages
  • haha
    586 mots | 3 pages
  • haha
    669 mots | 3 pages