Questo codice funziona:Perché rendere questo getter annullabile causa un errore di compilazione?
class Example
{
public Int32 Int32
{
get { return Int32.Parse("3"); }
}
}
Questo codice non può essere compilato: 'int'
class Example
{
public Int32? Int32
{
get { return Int32.Parse("3"); }
}
}
CS1061 non contiene una definizione per 'Parse' e nessun metodo di estensione 'Parse' che accetta un primo argomento di tipo 'int?' potrebbe essere trovato (le manca un un riferimento all'assembly direttiva using o?)
Il mio esempio può sembrare stupido, ma rende molto più senso se si utilizza immaginare un enum, come
public Choice? Choice { get { return Choice.One; } }
Nel secondo esempio, 'Int32' si riferisce alla proprietà' Int32' per non digitare 'System.Int32'. – PetSerAl