Type.IsValueType Proprietà
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.
Ottiene un valore che indica se è Type un tipo di valore.
public:
property bool IsValueType { bool get(); };
public bool IsValueType { get; }
member this.IsValueType : bool
Public ReadOnly Property IsValueType As Boolean
Valore della proprietà
true se è Type un tipo di valore; in caso contrario, false.
Implementazioni
Esempio
Nell'esempio seguente viene creata una variabile di tipo MyEnum, viene verificata la IsValueType proprietà e viene visualizzato il risultato.
using System;
// Declare an enum type.
enum NumEnum { One, Two }
public class Example
{
public static void Main(string []args)
{
bool flag = false;
NumEnum testEnum = NumEnum.One;
// Get the type of testEnum.
Type t = testEnum.GetType();
// Get the IsValueType property of the testEnum variable.
flag = t.IsValueType;
Console.WriteLine("{0} is a value type: {1}", t.FullName, flag);
}
}
// The example displays the following output:
// NumEnum is a value type: True
// Declare an enum type.
type NumEnum = One = 1 | Two = 2
let testEnum = NumEnum.One
// Get the type of testEnum.
let t = testEnum.GetType()
// Get the IsValueType property of the testEnum variable.
let flag = t.IsValueType
printfn $"{t.FullName} is a value type: {flag}"
// The example displays the following output:
// NumEnum is a value type: True
' Declare an enum type.
Enum NumEnum
One
Two
End Enum
Public Class Example
Public Shared Sub Main()
Dim flag As Boolean = False
Dim testEnum As NumEnum = NumEnum.One
' Get the type of myTestEnum.
Dim t As Type = testEnum.GetType()
' Get the IsValueType property of the myTestEnum variable.
flag = t.IsValueType()
Console.WriteLine("{0} is a value type: {1}", t.FullName, flag)
End Sub
End Class
' The example displays the following output:
' NumEnum is a value type: True
Commenti
I tipi valore sono tipi rappresentati come sequenze di bit; i tipi valore non sono classi o interfacce. I tipi valore vengono definiti "struct" in alcuni linguaggi di programmazione. Le enumerazioni sono un caso speciale di tipi valore.
Questa proprietà restituisce false per la ValueType classe , perché ValueType non è un tipo valore stesso. è la classe base per tutti i tipi valore e pertanto è possibile assegnarvi qualsiasi tipo di valore. Ciò non sarebbe possibile se ValueType stesso fosse un tipo di valore. I tipi valore vengono boxed quando vengono assegnati a un campo di tipo ValueType.
Questa proprietà restituisce true per le enumerazioni, ma non per il Enum tipo stesso. Per un esempio che illustra questo comportamento, vedere IsEnum.
Questa proprietà è di sola lettura.