Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

System.Drawing.Color als const definieren => Fehler

20 views
Skip to first unread message

Alberto Luca

unread,
Mar 28, 2010, 7:19:10 AM3/28/10
to
Hallo NewsGroup,

ich möchte bestimmte Farben allgemein definieren, jedoch als 'const', damit
kein Objektverweis erforderlich ist.
Wie kann ich dies erreichen?

derzeit:
public const System.Drawing.Color gcColor_FragenDefault =
System.Drawing.Color.Tomato;
=> Fehlermeldung: Der Typ "System.Drawing.Color" kann nicht als konstant
deklariert werden.

Besten Dank vorab!
Ciao, Alberto

Frank Dzaebel

unread,
Mar 28, 2010, 7:43:40 AM3/28/10
to
Hallo Alberto,

> ich möchte bestimmte Farben allgemein definieren, jedoch als 'const',
> damit kein Objektverweis erforderlich ist.
> Wie kann ich dies erreichen?

Zum Beispiel:

static public class Farben
{
/// <summary>
/// Ruft die Farbe mit dem ARGB Wert #FFFF6347 ab.
/// Die Standard-Dialogfarbe.
/// </summary>
static readonly public Color Standard = Color.Tomato;
}

(Abfruf dann etwa mit: Farben.Standard )

> public const System.Drawing.Color gcColor_FragenDefault =
> System.Drawing.Color.Tomato;
> => Fehlermeldung: Der Typ "System.Drawing.Color" kann nicht als konstant
> deklariert werden.

Color ist ein "struct". Bei dem in einer Konstantendeklaration angegebenen
Typ
muss es sich aber um byte, char, short, int, long, float, double, decimal,
bool, string,
einen Enum-Typ oder einen Verweistyp handeln, dem der Wert NULL zugewiesen
ist.
Jeder konstante Ausdruck muss einen Wert des Zieltyps oder eines Typs
liefern,
der implizit in den Zieltyp konvertiert werden kann.


ciao Frank
--
Dipl.Inf. Frank Dzaebel [MCP/MVP C#]
http://Dzaebel.NET

Alberto Luca

unread,
Mar 28, 2010, 12:39:52 PM3/28/10
to
Hallo Frank,

> static public class Farben
> {
> /// <summary>
> /// Ruft die Farbe mit dem ARGB Wert #FFFF6347 ab.
> /// Die Standard-Dialogfarbe.
> /// </summary>
> static readonly public Color Standard = Color.Tomato;
> }

besten Dank!
Funktioniert.

Ciao, Alberto

0 new messages