Passare un valore ad un array di strutture

lunedì 26 marzo 2012 - 14.38
Tag Elenco Tags  C#  |  Windows 7  |  Windows Vista

WinterMute Profilo | Newbie

Buongiorno. Ho definito un array di strutture partendo da una struttura. Non essendo ferratissimo di C# ho curiosato in giro ed ho messo insieme questo codice:

public struct Oggetto // Definisce un oggetto per il layout
{
int a, b, c, d, e, f, g;
Color h;
public Oggetto(int forma, int distanza, int inclinazione, int angolo, int larghezza, int altezza, int profondità, Color colore)
{
a = forma;
b = distanza;
c = inclinazione;
d = angolo;
e = larghezza;
f = altezza;
g = profondità;
h = colore;
}
};

public Oggetto[] layoutObject = new Oggetto [10] // definisce un array 10 oggetti da inserire nel layout
{
//Oggetto(forma, distanza, inclinazione, int angolo, int larghezza, int altezza, int profondità, Color colore)
new Oggetto(0, 10, 0, 0, 10, 10, 10, Color.Red),
new Oggetto(0, 10, 0, 0, 10, 10, 10, Color.Red),
new Oggetto(0, 10, 0, 0, 10, 10, 10, Color.Red),
new Oggetto(0, 10, 0, 0, 10, 10, 10, Color.Red),
new Oggetto(0, 10, 0, 0, 10, 10, 10, Color.Red),
new Oggetto(0, 10, 0, 0, 10, 10, 10, Color.Red),
new Oggetto(0, 10, 0, 0, 10, 10, 10, Color.Red),
new Oggetto(0, 10, 0, 0, 10, 10, 10, Color.Red),
new Oggetto(0, 10, 0, 0, 10, 10, 10, Color.Red),
new Oggetto(0, 10, 0, 0, 10, 10, 10, Color.Red),
};

fino a qui non ho errori
Però non riesco a passare un valore agli oggetti dell'array. Vorrei un tipo di istruzione del tipo layoutObject[1].colore = Color.Blue , ma non riesco...
Grazie in anticipo

andrestu Profilo | Expert

devi definire public i membri della struct oggetto.

Andrea Restucci - Web Developer
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2025
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5