Enum Classe
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Si tratta della classe base per le enumerazioni.
public ref class Enum abstract : ValueType, IComparable, IConvertible, IFormattable
public ref class Enum abstract : ValueType, IComparable, IConvertible, ISpanFormattable
public ref class Enum abstract : ValueType, IComparable, IFormattable
public abstract class Enum : ValueType, IComparable, IConvertible, IFormattable
public abstract class Enum : ValueType, IComparable, IConvertible, ISpanFormattable
[System.Serializable]
public abstract class Enum : ValueType, IComparable, IConvertible, IFormattable
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public abstract class Enum : ValueType, IComparable, IConvertible, IFormattable
public abstract class Enum : ValueType, IComparable, IFormattable
type Enum = class
inherit ValueType
interface IComparable
interface IConvertible
interface IFormattable
type Enum = class
inherit ValueType
interface IComparable
interface IConvertible
interface ISpanFormattable
interface IFormattable
[<System.Serializable>]
type Enum = class
inherit ValueType
interface IComparable
interface IFormattable
interface IConvertible
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type Enum = class
inherit ValueType
interface IComparable
interface IFormattable
interface IConvertible
type Enum = class
inherit ValueType
interface IComparable
interface IFormattable
Public MustInherit Class Enum
Inherits ValueType
Implements IComparable, IConvertible, IFormattable
Public MustInherit Class Enum
Inherits ValueType
Implements IComparable, IConvertible, ISpanFormattable
Public MustInherit Class Enum
Inherits ValueType
Implements IComparable, IFormattable
- Ereditarietà
- Derivato
- Attributi
- Implementazioni
Esempio
Nell'esempio seguente viene illustrato l'uso di un'enumerazione per rappresentare i valori denominati e un'altra enumerazione per rappresentare i campi di bit denominati.
using namespace System;
enum class Days
{
Saturday, Sunday, Monday, Tuesday, Wednesday, Thursday, Friday
};
enum class BoilingPoints
{
Celsius = 100,
Fahrenheit = 212
};
[Flags]
enum class Colors
{
Red = 1,
Green = 2,
Blue = 4,
Yellow = 8
};
int main()
{
Type^ weekdays = Days::typeid;
Type^ boiling = BoilingPoints::typeid;
Console::WriteLine( "The days of the week, and their corresponding values in the Days Enum are:" );
Array^ a = Enum::GetNames( weekdays );
Int32 i = 0;
do
{
Object^ o = a->GetValue( i );
Console::WriteLine( "{0,-11}= {1}", o->ToString(), Enum::Format( weekdays, Enum::Parse( weekdays, o->ToString() ), "d" ) );
}
while ( ++i < a->Length );
Console::WriteLine();
Console::WriteLine( "Enums can also be created which have values that represent some meaningful amount." );
Console::WriteLine( "The BoilingPoints Enum defines the following items, and corresponding values:" );
i = 0;
Array^ b = Enum::GetNames( boiling );
do
{
Object^ o = b->GetValue( i );
Console::WriteLine( "{0,-11}= {1}", o->ToString(), Enum::Format( boiling, Enum::Parse( boiling, o->ToString() ), "d" ) );
}
while ( ++i < b->Length );
Array^ c = Enum::GetNames( Colors::typeid );
Colors myColors = Colors::Red | Colors::Blue | Colors::Yellow;
Console::WriteLine();
Console::Write( "myColors holds a combination of colors. Namely:" );
for ( i = 0; i < 3; i++ )
Console::Write( " {0}", c->GetValue( i ) );
}
using System;
public class EnumTest {
enum Days { Saturday, Sunday, Monday, Tuesday, Wednesday, Thursday, Friday };
enum BoilingPoints { Celsius = 100, Fahrenheit = 212 };
[Flags]
enum Colors { Red = 1, Green = 2, Blue = 4, Yellow = 8 };
public static void Main() {
Type weekdays = typeof(Days);
Type boiling = typeof(BoilingPoints);
Console.WriteLine("The days of the week, and their corresponding values in the Days Enum are:");
foreach ( string s in Enum.GetNames(weekdays) )
Console.WriteLine( "{0,-11}= {1}", s, Enum.Format( weekdays, Enum.Parse(weekdays, s), "d"));
Console.WriteLine();
Console.WriteLine("Enums can also be created which have values that represent some meaningful amount.");
Console.WriteLine("The BoilingPoints Enum defines the following items, and corresponding values:");
foreach ( string s in Enum.GetNames(boiling) )
Console.WriteLine( "{0,-11}= {1}", s, Enum.Format(boiling, Enum.Parse(boiling, s), "d"));
Colors myColors = Colors.Red | Colors.Blue | Colors.Yellow;
Console.WriteLine();
Console.WriteLine("myColors holds a combination of colors. Namely: {0}", myColors);
}
}
open System
type Days =
| Saturday = 0
| Sunday = 1
| Monday = 2
| Tuesday = 3
| Wednesday = 4
| Thursday = 5
| Friday = 6
type BoilingPoints =
| Celsius = 100
| Fahrenheit = 212
[<Flags>]
type Colors =
| Red = 1
| Green = 2
| Blue = 4
| Yellow = 8
let weekdays = typeof<Days>
let boiling = typeof<BoilingPoints>
printfn "The days of the week, and their corresponding values in the Days Enum are:"
for s in Enum.GetNames weekdays do
printfn $"""{s,-11}= {Enum.Format(weekdays, Enum.Parse(weekdays, s), "d")}"""
printfn "\nEnums can also be created which have values that represent some meaningful amount."
printfn "The BoilingPoints Enum defines the following items, and corresponding values:"
for s in Enum.GetNames boiling do
printfn $"""{s,-11}= {Enum.Format(boiling, Enum.Parse(boiling, s), "d")}"""
let myColors = Colors.Red ||| Colors.Blue ||| Colors.Yellow
printfn $"\nmyColors holds a combination of colors. Namely: {myColors}"
Public Class EnumTest
Enum Days
Saturday
Sunday
Monday
Tuesday
Wednesday
Thursday
Friday
End Enum
Enum BoilingPoints
Celsius = 100
Fahrenheit = 212
End Enum
<Flags()> _
Enum Colors
Red = 1
Green = 2
Blue = 4
Yellow = 8
End Enum
Public Shared Sub Main()
Dim weekdays As Type = GetType(Days)
Dim boiling As Type = GetType(BoilingPoints)
Console.WriteLine("The days of the week, and their corresponding values in the Days Enum are:")
Dim s As String
For Each s In [Enum].GetNames(weekdays)
Console.WriteLine("{0,-11} = {1}", s, [Enum].Format(weekdays, [Enum].Parse(weekdays, s), "d"))
Next s
Console.WriteLine()
Console.WriteLine("Enums can also be created which have values that represent some meaningful amount.")
Console.WriteLine("The BoilingPoints Enum defines the following items, and corresponding values:")
For Each s In [Enum].GetNames(boiling)
Console.WriteLine("{0,-11} = {1}", s, [Enum].Format(boiling, [Enum].Parse(boiling, s), "d"))
Next s
Dim myColors As Colors = Colors.Red Or Colors.Blue Or Colors.Yellow
Console.WriteLine()
Console.WriteLine("myColors holds a combination of colors. Namely: {0}", myColors)
End Sub
End Class
Commenti
Un'enumerazione è un set di costanti denominate il cui tipo sottostante è qualsiasi tipo integrale. Se non viene dichiarato in modo esplicito alcun tipo sottostante, Int32 viene usato . Enum è la classe di base per tutte le enumerazioni in .NET Framework. I tipi di enumerazione sono definiti dalla enum
parola chiave in C#, dal Enum
costrutto ...End Enum
in Visual Basic e dalla type
parola chiave in F#.
Enum fornisce metodi per confrontare le istanze di questa classe, convertendo il valore di un'istanza nella relativa rappresentazione di stringa, convertendo la rappresentazione di stringa di un numero in un'istanza di questa classe e creando un'istanza di un'enumerazione e un valore specificati.
È anche possibile trattare un'enumerazione come campo di bit. Per altre informazioni, vedere la sezione Membri non esclusivi e l'attributo Flags e l'argomento FlagsAttribute .
In questo argomento
Creazione di un tipo di enumerazione Creazione di un'istanza di un tipo di enumerazione Procedure consigliate per l'enumerazione Esecuzione di operazioni con enumerazioniEsecuzione di conversioniAnalisi di valori di enumerazione Valori di enumerazioneIterando i membri di enumerazione Membri non esclusivi e l'attributo FlagsAggiunta di metodi di enumerazione
Creazione di un tipo di enumerazione
I linguaggi di programmazione forniscono in genere la sintassi per dichiarare un'enumerazione costituita da un set di costanti denominate e i relativi valori. Nell'esempio seguente viene illustrata la sintassi usata da C#, F# e Visual Basic per definire un'enumerazione. Crea un'enumerazione denominata ArrivalStatus
con tre membri: ArrivalStatus.Early
, ArrivalStatus.OnTime
e ArrivalStatus.Late
. Si noti che in tutti i casi, l'enumerazione non eredita in modo esplicito da Enum; la relazione di ereditarietà viene gestita in modo implicito dal compilatore.
public enum ArrivalStatus { Late=-1, OnTime=0, Early=1 };
type ArrivalStatus =
| Late = -1
| OnTime = 0
| Early = 1
Public Enum ArrivalStatus As Integer
Late = -1
OnTime = 0
Early = 1
End Enum
Avviso
Non è mai consigliabile creare un tipo di enumerazione il cui tipo sottostante è non integrale o Char. Sebbene sia possibile creare un tipo di enumerazione di questo tipo usando reflection, le chiamate al metodo che usano il tipo risultante non sono affidabili e possono anche generare eccezioni aggiuntive.
Creazione di un'istanza di un tipo di enumerazione
È possibile creare un'istanza di un tipo di enumerazione esattamente come si crea un'istanza di qualsiasi altro tipo di valore: dichiarando una variabile e assegnando una delle costanti dell'enumerazione. Nell'esempio seguente viene creata un'istanza di un oggetto il ArrivalStatus
cui valore è ArrivalStatus.OnTime
.
public class Example
{
public static void Main()
{
ArrivalStatus status = ArrivalStatus.OnTime;
Console.WriteLine("Arrival Status: {0} ({0:D})", status);
}
}
// The example displays the following output:
// Arrival Status: OnTime (0)
let status = ArrivalStatus.OnTime
printfn $"Arrival Status: {status} ({status:D})"
// The example displays the following output:
// Arrival Status: OnTime (0)
Public Module Example
Public Sub Main()
Dim status As ArrivalStatus = ArrivalStatus.OnTime
Console.WriteLine("Arrival Status: {0} ({0:D})", status)
End Sub
End Module
' The example displays the following output:
' Arrival Status: OnTime (0)
È anche possibile creare un'istanza di un valore di enumerazione nei modi seguenti:
Usando le funzionalità di un linguaggio di programmazione specifico per eseguire il cast (come in C#) o convertire (come in Visual Basic) un valore intero in un valore di enumerazione. Nell'esempio seguente viene creato un
ArrivalStatus
oggetto il cui valore èArrivalStatus.Early
in questo modo.ArrivalStatus status2 = (ArrivalStatus) 1; Console.WriteLine("Arrival Status: {0} ({0:D})", status2); // The example displays the following output: // Arrival Status: Early (1)
let status2 = enum<ArrivalStatus> 1 printfn $"Arrival Status: {status2} ({status2:D})" // The example displays the following output: // Arrival Status: Early (1)
Dim status2 As ArrivalStatus = CType(1, ArrivalStatus) Console.WriteLine("Arrival Status: {0} ({0:D})", status2) ' The example displays the following output: ' Arrival Status: Early (1)
Chiamando il costruttore implicito senza parametri. Come illustrato nell'esempio seguente, in questo caso il valore sottostante dell'istanza di enumerazione è 0. Tuttavia, questo non è necessariamente il valore di una costante valida nell'enumerazione.
ArrivalStatus status1 = new ArrivalStatus(); Console.WriteLine("Arrival Status: {0} ({0:D})", status1); // The example displays the following output: // Arrival Status: OnTime (0)
let status1 = ArrivalStatus() printfn $"Arrival Status: {status1} ({status1:D})" // The example displays the following output: // Arrival Status: OnTime (0)
Dim status1 As New ArrivalStatus() Console.WriteLine("Arrival Status: {0} ({0:D})", status1) ' The example displays the following output: ' Arrival Status: OnTime (0)
Chiamando il Parse metodo o TryParse per analizzare una stringa contenente il nome di una costante nell'enumerazione. Per altre informazioni, vedere la sezione Analisi dei valori di enumerazione .
Chiamando il ToObject metodo per convertire un valore integrale in un tipo di enumerazione. Per altre informazioni, vedere la sezione Esecuzione di conversioni .
Procedure consigliate per l'enumerazione
È consigliabile usare le procedure consigliate seguenti quando si definiscono i tipi di enumerazione:
Se non è stato definito un membro di enumerazione il cui valore è 0, è consigliabile creare una
None
costante enumerata. Per impostazione predefinita, la memoria usata per l'enumerazione viene inizializzata su zero da Common Language Runtime. Di conseguenza, se non si definisce una costante il cui valore è zero, l'enumerazione conterrà un valore illegale quando viene creato.Se esiste un caso predefinito ovvio che l'applicazione deve rappresentare, è consigliabile usare una costante enumerata il cui valore è zero per rappresentarlo. Se non esiste un caso predefinito, è consigliabile usare una costante enumerata il cui valore è zero per specificare il caso che non è rappresentato da alcuna delle altre costanti enumerate.
Non specificare costanti enumerate riservate per l'uso futuro.
Quando si definisce un metodo o una proprietà che accetta una costante enumerata come valore, è consigliabile convalidare il valore. Il motivo è che è possibile eseguire il cast di un valore numerico al tipo di enumerazione anche se tale valore numerico non è definito nell'enumerazione.
Procedure consigliate aggiuntive per i tipi di enumerazione le cui costanti sono campi bit sono elencati nella sezione Membri non esclusivi e nella sezione Attributi flag .
Esecuzione di operazioni con enumerazioni
Non è possibile definire nuovi metodi quando si crea un'enumerazione. Tuttavia, un tipo di enumerazione eredita un set completo di metodi statici e di istanza dalla Enum classe. Le sezioni seguenti esaminano la maggior parte di questi metodi, oltre a diversi altri metodi comunemente usati durante l'uso dei valori di enumerazione.
Esecuzione di conversioni
È possibile convertire tra un membro di enumerazione e il relativo tipo sottostante usando un cast (in C# e F#) o un operatore di conversione (in Visual Basic). In F#viene usata anche la enum
funzione. Nell'esempio seguente vengono usati operatori di cast o conversione per eseguire conversioni da un intero a un valore di enumerazione e da un valore di enumerazione a un intero.
int value3 = 2;
ArrivalStatus status3 = (ArrivalStatus) value3;
int value4 = (int) status3;
let value3 = 2
let status3 = enum<ArrivalStatus> value3
let value4 = int status3
Dim value3 As Integer = 2
Dim status3 As ArrivalStatus = CType(value3, ArrivalStatus)
Dim value4 As Integer = CInt(status3)
La Enum classe include anche un metodo che converte un ToObject valore di qualsiasi tipo integrale in un valore di enumerazione. Nell'esempio seguente viene usato il ToObject(Type, Int32) metodo per convertire un oggetto Int32 in un ArrivalStatus
valore. Si noti che, poiché il ToObject valore restituisce un valore di tipo Object, l'uso di un operatore di cast o conversione potrebbe comunque essere necessario per eseguire il cast dell'oggetto al tipo di enumerazione.
int number = -1;
ArrivalStatus arrived = (ArrivalStatus) ArrivalStatus.ToObject(typeof(ArrivalStatus), number);
let number = -1
let arrived = ArrivalStatus.ToObject(typeof<ArrivalStatus>, number) :?> ArrivalStatus
Dim number As Integer = -1
Dim arrived As ArrivalStatus = CType(ArrivalStatus.ToObject(GetType(ArrivalStatus), number), ArrivalStatus)
Quando si converte un intero in un valore di enumerazione, è possibile assegnare un valore che non è effettivamente un membro dell'enumerazione. Per evitare questo problema, è possibile passare l'intero al IsDefined metodo prima di eseguire la conversione. Nell'esempio seguente viene usato questo metodo per determinare se gli elementi in una matrice di valori integer possono essere convertiti in ArrivalStatus
valori.
using System;
public enum ArrivalStatus { Unknown=-3, Late=-1, OnTime=0, Early=1 };
public class Example
{
public static void Main()
{
int[] values = { -3, -1, 0, 1, 5, Int32.MaxValue };
foreach (var value in values)
{
ArrivalStatus status;
if (Enum.IsDefined(typeof(ArrivalStatus), value))
status = (ArrivalStatus) value;
else
status = ArrivalStatus.Unknown;
Console.WriteLine("Converted {0:N0} to {1}", value, status);
}
}
}
// The example displays the following output:
// Converted -3 to Unknown
// Converted -1 to Late
// Converted 0 to OnTime
// Converted 1 to Early
// Converted 5 to Unknown
// Converted 2,147,483,647 to Unknown
open System
type ArrivalStatus =
| Unknown = -3
| Late = -1
| OnTime = 0
| Early = 1
let values = [ -3; -1; 0; 1; 5; Int32.MaxValue ]
for value in values do
let status =
if Enum.IsDefined(typeof<ArrivalStatus>, value) then
enum value
else
ArrivalStatus.Unknown
printfn $"Converted {value:N0} to {status}"
// The example displays the following output:
// Converted -3 to Unknown
// Converted -1 to Late
// Converted 0 to OnTime
// Converted 1 to Early
// Converted 5 to Unknown
// Converted 2,147,483,647 to Unknown
Public Enum ArrivalStatus As Integer
Unknown = -3
Late = -1
OnTime = 0
Early = 1
End Enum
Module Example
Public Sub Main()
Dim values() As Integer = { -3, -1, 0, 1, 5, Int32.MaxValue }
For Each value In values
Dim status As ArrivalStatus
If [Enum].IsDefined(GetType(ArrivalStatus), value)
status = CType(value, ArrivalStatus)
Else
status = ArrivalStatus.Unknown
End If
Console.WriteLine("Converted {0:N0} to {1}", value, status)
Next
End Sub
End Module
' The example displays the following output:
' Converted -3 to Unknown
' Converted -1 to Late
' Converted 0 to OnTime
' Converted 1 to Early
' Converted 5 to Unknown
' Converted 2,147,483,647 to Unknown
Anche se la Enum classe fornisce implementazioni esplicite dell'interfaccia IConvertible per la conversione da un valore di enumerazione a un tipo integrale, è consigliabile usare i metodi della Convert classe, ad esempio ToInt32, per eseguire queste conversioni. Nell'esempio seguente viene illustrato come usare il GetUnderlyingType metodo insieme al Convert.ChangeType metodo per convertire un valore di enumerazione nel tipo sottostante. Si noti che questo esempio non richiede che il tipo sottostante dell'enumerazione sia noto in fase di compilazione.
ArrivalStatus status = ArrivalStatus.Early;
var number = Convert.ChangeType(status, Enum.GetUnderlyingType(typeof(ArrivalStatus)));
Console.WriteLine("Converted {0} to {1}", status, number);
// The example displays the following output:
// Converted Early to 1
let status = ArrivalStatus.Early
let number = Convert.ChangeType(status, Enum.GetUnderlyingType typeof<ArrivalStatus>)
printfn $"Converted {status} to {number}"
// The example displays the following output:
// Converted Early to 1
Dim status As ArrivalStatus = ArrivalStatus.Early
Dim number = Convert.ChangeType(status, [Enum].GetUnderlyingType(GetType(ArrivalStatus)))
Console.WriteLine("Converted {0} to {1}", status, number)
' The example displays the following output:
' Converted Early to 1
Analisi dei valori di enumerazione
I Parse metodi e TryParse consentono di convertire la rappresentazione stringa di un valore di enumerazione in tale valore. La rappresentazione stringa può essere il nome o il valore sottostante di una costante di enumerazione. Si noti che i metodi di analisi convertono correttamente rappresentazioni stringa di numeri che non sono membri di un'enumerazione specifica se le stringhe possono essere convertite in un valore del tipo sottostante dell'enumerazione. Per evitare questo problema, il IsDefined metodo può essere chiamato per assicurarsi che il risultato del metodo di analisi sia un valore di enumerazione valido. L'esempio illustra questo approccio e illustra le chiamate ai Parse(Type, String) metodi e Enum.TryParse<TEnum>(String, TEnum) . Si noti che il metodo di analisi non generico restituisce un oggetto che potrebbe essere necessario eseguire il cast (in C# e F#) o convertire (in Visual Basic) nel tipo di enumerazione appropriato.
string number = "-1";
string name = "Early";
try {
ArrivalStatus status1 = (ArrivalStatus) Enum.Parse(typeof(ArrivalStatus), number);
if (!(Enum.IsDefined(typeof(ArrivalStatus), status1)))
status1 = ArrivalStatus.Unknown;
Console.WriteLine("Converted '{0}' to {1}", number, status1);
}
catch (FormatException) {
Console.WriteLine("Unable to convert '{0}' to an ArrivalStatus value.",
number);
}
ArrivalStatus status2;
if (Enum.TryParse<ArrivalStatus>(name, out status2)) {
if (!(Enum.IsDefined(typeof(ArrivalStatus), status2)))
status2 = ArrivalStatus.Unknown;
Console.WriteLine("Converted '{0}' to {1}", name, status2);
}
else {
Console.WriteLine("Unable to convert '{0}' to an ArrivalStatus value.",
number);
}
// The example displays the following output:
// Converted '-1' to Late
// Converted 'Early' to Early
let number = "-1"
let name = "Early"
try
let status1 = Enum.Parse(typeof<ArrivalStatus>, number) :?> ArrivalStatus
let status1 =
if not (Enum.IsDefined(typeof<ArrivalStatus>, status1) ) then
ArrivalStatus.Unknown
else
status1
printfn $"Converted '{number}' to {status1}"
with :? FormatException ->
printfn $"Unable to convert '{number}' to an ArrivalStatus value."
match Enum.TryParse<ArrivalStatus> name with
| true, status2 ->
let status2 =
if not (Enum.IsDefined(typeof<ArrivalStatus>, status2) ) then
ArrivalStatus.Unknown
else
status2
printfn $"Converted '{name}' to {status2}"
| _ ->
printfn $"Unable to convert '{number}' to an ArrivalStatus value."
// The example displays the following output:
// Converted '-1' to Late
// Converted 'Early' to Early
Dim number As String = "-1"
Dim name As String = "Early"
Dim invalid As String = "32"
Try
Dim status1 As ArrivalStatus = CType([Enum].Parse(GetType(ArrivalStatus), number), ArrivalStatus)
If Not [Enum].IsDefined(GetType(ArrivalStatus), status1) Then status1 = ArrivalStatus.Unknown
Console.WriteLine("Converted '{0}' to {1}", number, status1)
Catch e As FormatException
Console.WriteLine("Unable to convert '{0}' to an ArrivalStatus value.",
number)
End Try
Dim status2 As ArrivalStatus
If [Enum].TryParse(Of ArrivalStatus)(name, status2) Then
If Not [Enum].IsDefined(GetType(ArrivalStatus), status2) Then status2 = ArrivalStatus.Unknown
Console.WriteLine("Converted '{0}' to {1}", name, status2)
Else
Console.WriteLine("Unable to convert '{0}' to an ArrivalStatus value.",
number)
End If
' The example displays the following output:
' Converted '-1' to Late
' Converted 'Early' to Early
Formattazione dei valori di enumerazione
È possibile convertire i valori di enumerazione nelle relative rappresentazioni di stringa chiamando il metodo statico Format , nonché gli overload del metodo dell'istanza ToString . È possibile usare una stringa di formato per controllare il modo preciso in cui un valore di enumerazione è rappresentato come stringa. Per altre informazioni, vedere Stringhe di formato di enumerazione. Nell'esempio seguente vengono usate le stringhe di formato di enumerazione supportate ("G" o "g", "D" o "d", "X" o "x" e "F" o "f" ) per convertire un membro dell'enumerazione ArrivalStatus
nelle relative rappresentazioni di stringa.
string[] formats= { "G", "F", "D", "X"};
ArrivalStatus status = ArrivalStatus.Late;
foreach (var fmt in formats)
Console.WriteLine(status.ToString(fmt));
// The example displays the following output:
// Late
// Late
// -1
// FFFFFFFF
let formats = [ "G"; "F"; "D"; "X" ]
let status = ArrivalStatus.Late
for fmt in formats do
printfn $"{status.ToString fmt}"
// The example displays the following output:
// Late
// Late
// -1
// FFFFFFFF
Dim formats() As String = { "G", "F", "D", "X"}
Dim status As ArrivalStatus = ArrivalStatus.Late
For Each fmt As String In formats
Console.WriteLine(status.ToString(fmt))
Next
' The example displays the following output:
' Late
' Late
' -1
' FFFFFFFF
Iterazione dei membri dell'enumerazione
Il Enum tipo non implementa l'interfaccia oIEnumerable<T>, che consente di eseguire l'iterazione IEnumerable dei membri di una raccolta usando un foreach
costrutto (in C#), (in F#) for..in
o For Each
(in Visual Basic). Tuttavia, è possibile enumerare i membri in uno dei due modi.
È possibile chiamare il GetNames metodo per recuperare una matrice di stringhe contenente i nomi dei membri dell'enumerazione. Successivamente, per ogni elemento della matrice di stringhe, è possibile chiamare il Parse metodo per convertire la stringa nel valore di enumerazione equivalente. Questo approccio viene illustrato nell'esempio seguente:
string[] names = Enum.GetNames(typeof(ArrivalStatus)); Console.WriteLine("Members of {0}:", typeof(ArrivalStatus).Name); Array.Sort(names); foreach (var name in names) { ArrivalStatus status = (ArrivalStatus) Enum.Parse(typeof(ArrivalStatus), name); Console.WriteLine(" {0} ({0:D})", status); } // The example displays the following output: // Members of ArrivalStatus: // Early (1) // Late (-1) // OnTime (0) // Unknown (-3)
let names = Enum.GetNames typeof<ArrivalStatus> printfn $"Members of {nameof ArrivalStatus}:" let names = Array.sort names for name in names do let status = Enum.Parse(typeof<ArrivalStatus>, name) :?> ArrivalStatus printfn $" {status} ({status:D})" // The example displays the following output: // Members of ArrivalStatus: // Early (1) // Late (-1) // OnTime (0) // Unknown (-3)
Dim names() As String = [Enum].GetNames(GetType(ArrivalStatus)) Console.WriteLine("Members of {0}:", GetType(ArrivalStatus).Name) Array.Sort(names) For Each name In names Dim status As ArrivalStatus = CType([Enum].Parse(GetType(ArrivalStatus), name), ArrivalStatus) Console.WriteLine(" {0} ({0:D})", status) Next ' The example displays the following output: ' Members of ArrivalStatus: ' Early (1) ' Late (-1) ' OnTime (0) ' Unknown (-3)
È possibile chiamare il GetValues metodo per recuperare una matrice contenente i valori sottostanti nell'enumerazione. Successivamente, per ogni elemento della matrice, è possibile chiamare il metodo per convertire l'intero ToObject nel relativo valore di enumerazione equivalente. Questo approccio viene illustrato nell'esempio seguente:
var values = Enum.GetValues(typeof(ArrivalStatus)); Console.WriteLine("Members of {0}:", typeof(ArrivalStatus).Name); foreach (ArrivalStatus status in values) { Console.WriteLine(" {0} ({0:D})", status); } // The example displays the following output: // Members of ArrivalStatus: // OnTime (0) // Early (1) // Unknown (-3) // Late (-1)
let values = Enum.GetValues typeof<ArrivalStatus> printfn $"Members of {nameof ArrivalStatus}:" for status in values do printfn $" {status} ({status:D})" // The example displays the following output: // Members of ArrivalStatus: // OnTime (0) // Early (1) // Unknown (-3) // Late (-1)
Dim values = [Enum].GetValues(GetType(ArrivalStatus)) Console.WriteLine("Members of {0}:", GetType(ArrivalStatus).Name) For Each value In values Dim status As ArrivalStatus = CType([Enum].ToObject(GetType(ArrivalStatus), value), ArrivalStatus) Console.WriteLine(" {0} ({0:D})", status) Next ' The example displays the following output: ' Members of ArrivalStatus: ' OnTime (0) ' Early (1) ' Unknown (-3) ' Late (-1)
Membri non esclusivi e l'attributo Flags
Un uso comune di un'enumerazione consiste nel rappresentare un set di valori reciprocamente esclusivi. Ad esempio, un'istanza ArrivalStatus
può avere un valore di Early
, OnTime
o Late
. Non ha senso per il valore di un'istanza ArrivalStatus
di riflettere più costanti di enumerazione.
In altri casi, tuttavia, il valore di un oggetto enumerazione può includere più membri di enumerazione e ogni membro rappresenta un campo bit nel valore di enumerazione. L'attributo FlagsAttribute può essere usato per indicare che l'enumerazione è costituita da campi bit. Ad esempio, un'enumerazione denominata Pets
può essere usata per indicare i tipi di animali domestici in una famiglia. Può essere definito come segue.
[Flags] public enum Pets { None=0, Dog=1, Cat=2, Bird=4, Rodent=8,
Reptile=16, Other=32 };
[<Flags>]
type Pets =
| None = 0
| Dog = 1
| Cat = 2
| Bird = 4
| Rodent = 8
| Reptile = 16
| Other = 32
<Flags> Public Enum Pets As Integer
None = 0
Dog = 1
Cat = 2
Bird = 4
Rodent = 8
Reptile = 16
Other = 32
End Enum
L'enumerazione Pets
può quindi essere usata come illustrato nell'esempio seguente.
Pets familyPets = Pets.Dog | Pets.Cat;
Console.WriteLine("Pets: {0:G} ({0:D})", familyPets);
// The example displays the following output:
// Pets: Dog, Cat (3)
let familyPets = Pets.Dog ||| Pets.Cat
printfn $"Pets: {familyPets:G} ({familyPets:D})"
// The example displays the following output:
// Pets: Dog, Cat (3)
Dim familyPets As Pets = Pets.Dog Or Pets.Cat
Console.WriteLine("Pets: {0:G} ({0:D})", familyPets)
' The example displays the following output:
' Pets: Dog, Cat (3)
Le procedure consigliate seguenti devono essere usate durante la definizione di un'enumerazione bit per bit e l'applicazione dell'attributo FlagsAttribute .
Usare l'attributo personalizzato per un'enumerazione FlagsAttribute solo se un'operazione bit per bit (AND, OR, EXCLUSIVE OR) deve essere eseguita su un valore numerico.
Definire costanti di enumerazione in poteri di due, ovvero 1, 2, 4, 8 e così via. Ciò significa che i singoli flag nelle costanti di enumerazione combinate non si sovrappongono.
È consigliabile creare una costante enumerata per le combinazioni di flag comunemente usate. Ad esempio, se si dispone di un'enumerazione usata per le operazioni di I/O file che contiene le costanti
Read = 1
enumerate eWrite = 2
, è consigliabile creare la costanteReadWrite = Read OR Write
enumerata , che combina i flag eWrite
.Read
Inoltre, l'operazione OR bit per bit usata per combinare i flag può essere considerata un concetto avanzato in alcune circostanze che non devono essere necessarie per attività semplici.Prestare attenzione se si definisce un numero negativo come costante enumerata di flag perché molte posizioni flag potrebbero essere impostate su 1, che potrebbero causare confusione nel codice e incoraggiare gli errori di codifica.
Un modo pratico per verificare se un flag è impostato in un valore numerico consiste nel chiamare il metodo di istanza HasFlag , come illustrato nell'esempio seguente.
Pets familyPets = Pets.Dog | Pets.Cat; if (familyPets.HasFlag(Pets.Dog)) Console.WriteLine("The family has a dog."); // The example displays the following output: // The family has a dog.
let familyPets = Pets.Dog ||| Pets.Cat if familyPets.HasFlag Pets.Dog then printfn "The family has a dog." // The example displays the following output: // The family has a dog.
Dim familyPets As Pets = Pets.Dog Or Pets.Cat If familyPets.HasFlag(Pets.Dog) Then Console.WriteLine("The family has a dog.") End If ' The example displays the following output: ' The family has a dog.
Equivale a eseguire un'operazione AND bit per bit tra il valore numerico e la costante enumerata del flag, che imposta tutti i bit nel valore numerico su zero che non corrispondono al flag e quindi verifica se il risultato di tale operazione è uguale alla costante enumerata del flag. Questo è illustrato nell'esempio seguente.
Pets familyPets = Pets.Dog | Pets.Cat; if ((familyPets & Pets.Dog) == Pets.Dog) Console.WriteLine("The family has a dog."); // The example displays the following output: // The family has a dog.
let familyPets = Pets.Dog ||| Pets.Cat if (familyPets &&& Pets.Dog) = Pets.Dog then printfn "The family has a dog." // The example displays the following output: // The family has a dog.
Dim familyPets As Pets = Pets.Dog Or Pets.Cat If familyPets And Pets.Dog = Pets.Dog Then Console.WriteLine("The family has a dog.") End If ' The example displays the following output: ' The family has a dog.
Usare
None
come nome della costante enumerata del flag il cui valore è zero. Non è possibile usare laNone
costante enumerata in un'operazione AND bit per bit per testare un flag perché il risultato è sempre zero. È tuttavia possibile eseguire un confronto logico, non bit per bit, tra il valore numerico e laNone
costante enumerata per determinare se vengono impostati eventuali bit nel valore numerico. Questo è illustrato nell'esempio seguente.Pets familyPets = Pets.Dog | Pets.Cat; if (familyPets == Pets.None) Console.WriteLine("The family has no pets."); else Console.WriteLine("The family has pets."); // The example displays the following output: // The family has pets.
let familyPets = Pets.Dog ||| Pets.Cat if familyPets = Pets.None then printfn "The family has no pets." else printfn "The family has pets." // The example displays the following output: // The family has pets.
Dim familyPets As Pets = Pets.Dog Or Pets.Cat If familyPets = Pets.None Then Console.WriteLine("The family has no pets.") Else Console.WriteLine("The family has pets.") End If ' The example displays the following output: ' The family has pets.
Non definire un valore di enumerazione esclusivamente per eseguire il mirroring dello stato dell'enumerazione stessa. Ad esempio, non definire una costante enumerata che contrassegna semplicemente la fine dell'enumerazione. Se è necessario determinare l'ultimo valore dell'enumerazione, verificare in modo esplicito tale valore. È inoltre possibile eseguire un controllo intervallo per la prima e l'ultima costante enumerata se tutti i valori all'interno dell'intervallo sono validi.
Aggiunta di metodi di enumerazione
Poiché i tipi di enumerazione sono definiti dalle strutture del linguaggio, ad enum
esempio (C#) e Enum
(Visual Basic), non è possibile definire metodi personalizzati per un tipo di enumerazione diverso da quelli ereditati dalla Enum classe. È tuttavia possibile usare i metodi di estensione per aggiungere funzionalità a un tipo di enumerazione specifico.
Nell'esempio seguente, l'enumerazione Grades
rappresenta il voto che uno studente potrebbe ricevere in un corso. Il metodo di estensione denominato Passing
viene aggiunto al tipo Grades
in modo che ogni istanza di tale tipo ora "sa" se rappresenta un voto sufficiente oppure no. La Extensions
classe contiene anche una variabile di lettura statica che definisce il livello minimo di passaggio. Il valore restituito del Passing
metodo di estensione riflette il valore corrente di tale variabile.
using System;
// Define an enumeration to represent student grades.
public enum Grades { F = 0, D = 1, C = 2, B = 3, A = 4 };
// Define an extension method for the Grades enumeration.
public static class Extensions
{
public static Grades minPassing = Grades.D;
public static bool Passing(this Grades grade)
{
return grade >= minPassing;
}
}
class Example
{
static void Main()
{
Grades g1 = Grades.D;
Grades g2 = Grades.F;
Console.WriteLine("{0} {1} a passing grade.", g1, g1.Passing() ? "is" : "is not");
Console.WriteLine("{0} {1} a passing grade.", g2, g2.Passing() ? "is" : "is not");
Extensions.minPassing = Grades.C;
Console.WriteLine("\nRaising the bar!\n");
Console.WriteLine("{0} {1} a passing grade.", g1, g1.Passing() ? "is" : "is not");
Console.WriteLine("{0} {1} a passing grade.", g2, g2.Passing() ? "is" : "is not");
}
}
// The exmaple displays the following output:
// D is a passing grade.
// F is not a passing grade.
//
// Raising the bar!
//
// D is not a passing grade.
// F is not a passing grade.
open System
open System.Runtime.CompilerServices
// Define an enumeration to represent student grades.
type Grades =
| F = 0
| D = 1
| C = 2
| B = 3
| A = 4
let mutable minPassing = Grades.D
// Define an extension method for the Grades enumeration.
[<Extension>]
type Extensions =
[<Extension>]
static member Passing(grade) = grade >= minPassing
let g1 = Grades.D
let g2 = Grades.F
printfn $"""{g1} {if g1.Passing() then "is" else "is not"} a passing grade."""
printfn $"""{g2} {if g2.Passing() then "is" else "is not"} a passing grade."""
minPassing <- Grades.C
printfn "\nRaising the bar!\n"
printfn $"""{g1} {if g1.Passing() then "is" else "is not"} a passing grade."""
printfn $"""{g2} {if g2.Passing() then "is" else "is not"} a passing grade."""
// The exmaple displays the following output:
// D is a passing grade.
// F is not a passing grade.
//
// Raising the bar!
//
// D is not a passing grade.
// F is not a passing grade.
Imports System.Runtime.CompilerServices
' Define an enumeration to represent student grades.
Public Enum Grades As Integer
F = 0
D = 1
C = 2
B = 3
A = 4
End Enum
' Define an extension method for the Grades enumeration.
Public Module Extensions
Public minPassing As Grades = Grades.D
<Extension>
Public Function Passing(grade As Grades) As Boolean
Return grade >= minPassing
End Function
End Module
Public Module Example
Public Sub Main()
Dim g1 As Grades = Grades.D
Dim g2 As Grades = Grades.F
Console.WriteLine("{0} {1} a passing grade.",
g1, If(g1.Passing(), "is", "is not"))
Console.WriteLine("{0} {1} a passing grade.",
g2, If(g2.Passing(), "is", "is not"))
Console.WriteLine()
Extensions.minPassing = Grades.C
Console.WriteLine("Raising the bar!")
Console.WriteLine()
Console.WriteLine("{0} {1} a passing grade.",
g1, If(g1.Passing(), "is", "is not"))
Console.WriteLine("{0} {1} a passing grade.",
g2, If(g2.Passing(), "is", "is not"))
End Sub
End Module
' The exmaple displays the following output:
' D is a passing grade.
' F is not a passing grade.
'
' Raising the bar!
'
' D is not a passing grade.
' F is not a passing grade.
Costruttori
Enum() |
Inizializza una nuova istanza della classe Enum. |
Metodi
CompareTo(Object) |
Confronta questa istanza con un oggetto specificato e restituisce un'indicazione dei valori relativi. |
Equals(Object) |
Restituisce un valore che indica se questa istanza è uguale a un oggetto specificato. |
Format(Type, Object, String) |
Converte il valore specificato di un determinato tipo enumerato nella rappresentazione di stringa equivalente, secondo il formato specificato. |
GetHashCode() |
Viene restituito il codice hash per il valore dell'istanza. |
GetName(Type, Object) |
Restituisce il nome della costante nell'enumerazione del valore specificato. |
GetName<TEnum>(TEnum) |
Recupera il nome della costante nel tipo di enumerazione del valore specificato. |
GetNames(Type) |
Restituisce una matrice dei nomi delle costanti in una enumerazione specificata. |
GetNames<TEnum>() |
Recupera una matrice dei nomi delle costanti in un tipo di enumerazione specificato. |
GetType() |
Ottiene l'oggetto Type dell'istanza corrente. (Ereditato da Object) |
GetTypeCode() |
Restituisce il codice del tipo sottostante di questo membro di enumerazione. |
GetUnderlyingType(Type) |
Restituisce il tipo sottostante dell'enumerazione specificata. |
GetValues(Type) |
Restituisce una matrice dei valori delle costanti in una enumerazione specificata. |
GetValues<TEnum>() |
Recupera una matrice dei valori delle costanti in un tipo di enumerazione specificato. |
GetValuesAsUnderlyingType(Type) |
Recupera una matrice dei valori delle costanti del tipo sottostante in un'enumerazione specificata. |
GetValuesAsUnderlyingType<TEnum>() |
Recupera una matrice dei valori delle costanti del tipo sottostante in un tipo di enumerazione specificato. |
HasFlag(Enum) |
Determina se uno o più campi di bit vengono impostati nell'istanza corrente. |
IsDefined(Type, Object) |
Restituisce un valore booleano se in un'enumerazione specificata esiste un determinato valore integrale o il relativo nome sotto forma di stringa. |
IsDefined<TEnum>(TEnum) |
Restituisce un valore booleano se in un'enumerazione specificata esiste un determinato valore integrale o il relativo nome sotto forma di stringa. |
MemberwiseClone() |
Crea una copia superficiale dell'oggetto Object corrente. (Ereditato da Object) |
Parse(Type, ReadOnlySpan<Char>) |
Converte l'intervallo di rappresentazione di caratteri del nome o del valore numerico di una o più costanti enumerate in un oggetto enumerato equivalente. |
Parse(Type, ReadOnlySpan<Char>, Boolean) |
Converte l'intervallo di rappresentazione di caratteri del nome o del valore numerico di una o più costanti enumerate in un oggetto enumerato equivalente. Un parametro specifica se l'operazione verrà eseguita senza distinzione tra maiuscole e minuscole. |
Parse(Type, String) |
Converte la rappresentazione di stringa del nome o del valore numerico di una o più costanti enumerate in un oggetto enumerato equivalente. |
Parse(Type, String, Boolean) |
Converte la rappresentazione di stringa del nome o del valore numerico di una o più costanti enumerate in un oggetto enumerato equivalente. Un parametro specifica se l'operazione verrà eseguita senza distinzione tra maiuscole e minuscole. |
Parse<TEnum>(ReadOnlySpan<Char>) |
Converte l'intervallo di caratteri di rappresentazione del nome o del valore numerico di una o più costanti enumerate specificate da |
Parse<TEnum>(ReadOnlySpan<Char>, Boolean) |
Converte l'intervallo di caratteri di rappresentazione del nome o del valore numerico di una o più costanti enumerate specificate da |
Parse<TEnum>(String) |
Converte la rappresentazione di stringa del nome o del valore numerico di una o più costanti enumerate specificate da |
Parse<TEnum>(String, Boolean) |
Converte la rappresentazione di stringa del nome o del valore numerico di una o più costanti enumerate specificate da |
ToObject(Type, Byte) |
Converte l'intero senza segno a 8 bit specificato in un membro di enumerazione. |
ToObject(Type, Int16) |
Converte l'intero con segno a 16 bit specificato in un membro di enumerazione. |
ToObject(Type, Int32) |
Converte l'intero con segno a 32 bit specificato in un membro di enumerazione. |
ToObject(Type, Int64) |
Converte l'intero con segno a 64 bit specificato in un membro di enumerazione. |
ToObject(Type, Object) |
Converte l'oggetto specificato con un valore intero in un membro di enumerazione. |
ToObject(Type, SByte) |
Converte il valore dell'intero con segno a 8 bit specificato in un membro di enumerazione. |
ToObject(Type, UInt16) |
Converte il valore dell'intero senza segno a 16 bit specificato in un membro di enumerazione. |
ToObject(Type, UInt32) |
Converte il valore dell'intero senza segno a 32 bit specificato in un membro di enumerazione. |
ToObject(Type, UInt64) |
Converte il valore dell'intero senza segno a 64 bit specificato in un membro di enumerazione. |
ToString() |
Converte il valore dell'istanza corrente nell'equivalente rappresentazione di stringa. |
ToString(IFormatProvider) |
Obsoleta.
Obsoleta.
L'overload di questo metodo è obsoleto; usare ToString(). |
ToString(String) |
Converte il valore dell'istanza corrente nella rappresentazione di stringa equivalente, usando il formato specificato. |
ToString(String, IFormatProvider) |
Obsoleta.
Obsoleta.
L'overload di questo metodo è obsoleto; usare ToString(String). |
TryFormat<TEnum>(TEnum, Span<Char>, Int32, ReadOnlySpan<Char>) |
Prova a formattare il valore dell'istanza del tipo enumerato nell'intervallo specificato di caratteri. |
TryParse(Type, ReadOnlySpan<Char>, Boolean, Object) |
Converte l'intervallo di rappresentazione di caratteri del nome o del valore numerico di una o più costanti enumerate in un oggetto enumerato equivalente. Un parametro specifica se l'operazione verrà eseguita senza distinzione tra maiuscole e minuscole. |
TryParse(Type, ReadOnlySpan<Char>, Object) |
Converte l'intervallo di rappresentazione di caratteri del nome o del valore numerico di una o più costanti enumerate in un oggetto enumerato equivalente. |
TryParse(Type, String, Boolean, Object) |
Converte la rappresentazione di stringa del nome o del valore numerico di una o più costanti enumerate in un oggetto enumerato equivalente. |
TryParse(Type, String, Object) |
Converte la rappresentazione di stringa del nome o del valore numerico di una o più costanti enumerate in un oggetto enumerato equivalente. |
TryParse<TEnum>(ReadOnlySpan<Char>, Boolean, TEnum) |
Converte la rappresentazione di stringa del nome o del valore numerico di una o più costanti enumerate in un oggetto enumerato equivalente. Un parametro specifica se l'operazione verrà eseguita con distinzione tra maiuscole e minuscole. Il valore restituito indica se la conversione è riuscita. |
TryParse<TEnum>(ReadOnlySpan<Char>, TEnum) |
Converte la rappresentazione di stringa del nome o del valore numerico di una o più costanti enumerate in un oggetto enumerato equivalente. |
TryParse<TEnum>(String, Boolean, TEnum) |
Converte la rappresentazione di stringa del nome o del valore numerico di una o più costanti enumerate in un oggetto enumerato equivalente. Un parametro specifica se l'operazione verrà eseguita con distinzione tra maiuscole e minuscole. Il valore restituito indica se la conversione è riuscita. |
TryParse<TEnum>(String, TEnum) |
Converte la rappresentazione di stringa del nome o del valore numerico di una o più costanti enumerate in un oggetto enumerato equivalente. Il valore restituito indica se la conversione è riuscita. |
Implementazioni dell'interfaccia esplicita
IConvertible.GetTypeCode() |
Restituisce il codice del tipo di questa istanza di Enum. |
IConvertible.ToBoolean(IFormatProvider) |
Converte il valore corrente in un valore booleano basato sul tipo sottostante. |
IConvertible.ToByte(IFormatProvider) |
Converte il valore corrente in un intero senza segno a 8 bit basato sul tipo sottostante. |
IConvertible.ToChar(IFormatProvider) |
Converte il valore corrente in un carattere Unicode basato sul tipo sottostante. |
IConvertible.ToDateTime(IFormatProvider) |
Converte il valore corrente in un oggetto DateTime basato sul tipo sottostante. |
IConvertible.ToDecimal(IFormatProvider) |
Converte il valore corrente in un oggetto Decimal basato sul tipo sottostante. |
IConvertible.ToDouble(IFormatProvider) |
Converte il valore corrente in un numero a virgola mobile e precisione doppia basato sul tipo sottostante. |
IConvertible.ToInt16(IFormatProvider) |
Converte il valore corrente in un intero con segno a 16 bit basato sul tipo sottostante. |
IConvertible.ToInt32(IFormatProvider) |
Converte il valore corrente in un intero con segno a 32 bit basato sul tipo sottostante. |
IConvertible.ToInt64(IFormatProvider) |
Converte il valore corrente in un intero con segno a 64 bit basato sul tipo sottostante. |
IConvertible.ToSByte(IFormatProvider) |
Converte il valore corrente in un intero con segno a 8 bit basato sul tipo sottostante. |
IConvertible.ToSingle(IFormatProvider) |
Converte il valore corrente in un numero a virgola mobile e con precisione singola in base al tipo sottostante. |
IConvertible.ToString(IFormatProvider) |
Obsoleta.
L'overload di questo metodo è obsoleto. Usare ToString() in alternativa. |
IConvertible.ToType(Type, IFormatProvider) |
Converte il valore corrente in un tipo specificato basato sul tipo sottostante. |
IConvertible.ToUInt16(IFormatProvider) |
Converte il valore corrente in un intero senza segno a 16 bit basato sul tipo sottostante. |
IConvertible.ToUInt32(IFormatProvider) |
Converte il valore corrente in un intero senza segno a 32 bit basato sul tipo sottostante. |
IConvertible.ToUInt64(IFormatProvider) |
Converte il valore corrente in un intero senza segno a 64 bit basato sul tipo sottostante. |
IFormattable.ToString(String, IFormatProvider) |
Obsoleta.
L'overload di questo metodo è obsoleto; usare ToString(String). |
ISpanFormattable.TryFormat(Span<Char>, Int32, ReadOnlySpan<Char>, IFormatProvider) |
Prova a formattare il valore dell'enumerazione nell'intervallo specificato di caratteri. |
Si applica a
Thread safety
Questo tipo è thread-safe.
Vedi anche
Commenti e suggerimenti
Invia e visualizza il feedback per