Ler en inglés

Compartir por


Type.IsPrimitive Propiedad

Definición

Obtiene un valor que indica si el objeto Type es uno de los tipos primitivos.

C#
public bool IsPrimitive { get; }

Valor de propiedad

Es true si Type es uno de los tipos primitivos; en caso contrario, es false.

Implementaciones

Ejemplos

En el ejemplo siguiente se muestran las IsContextfulpropiedades , IsMarshalByRefy IsPrimitive de la Type clase . Comprueba si el tipo especificado se puede hospedar en el contexto, si se puede serializar por referencia y si el tipo es un tipo de datos primitivo.

C#
using System;
using System.Runtime.Remoting.Contexts;

public class ContextBoundClass: ContextBoundObject
{
    public string Value = "The Value property.";
}

public class Example
{
    public static void Main()
    {
         // Determine whether the types can be hosted in a Context.
         Console.WriteLine("The IsContextful property for the {0} type is {1}.",
                           typeof(Example).Name, typeof(Example).IsContextful);
         Console.WriteLine("The IsContextful property for the {0} type is {1}.",
                           typeof(ContextBoundClass).Name, typeof(ContextBoundClass).IsContextful);

         // Determine whether the types are marshalled by reference.
         Console.WriteLine("The IsMarshalByRef property of {0} is {1}.",
                           typeof(Example).Name, typeof(Example).IsMarshalByRef);
         Console.WriteLine("The IsMarshalByRef property of {0} is {1}.",
                           typeof(ContextBoundClass).Name, typeof(ContextBoundClass).IsMarshalByRef);

         // Determine whether the types are primitive datatypes.
         Console.WriteLine("{0} is a primitive data type: {1}.",
                           typeof(int).Name, typeof(int).IsPrimitive);
         Console.WriteLine("{0} is a primitive data type: {1}.",
                           typeof(string).Name, typeof(string).IsPrimitive);
    }
}
// The example displays the following output:
//    The IsContextful property for the Example type is False.
//    The IsContextful property for the ContextBoundClass type is True.
//    The IsMarshalByRef property of Example is False.
//    The IsMarshalByRef property of ContextBoundClass is True.
//    Int32 is a primitive data type: True.
//    String is a primitive data type: False.

Comentarios

Los tipos primitivos son Boolean, , SByteByte, UInt16UInt32Int16Int32, UInt64Int64UIntPtrCharIntPtr, , Doubley .Single

Si el objeto actual Type representa un tipo genérico o un parámetro de tipo en la definición de un tipo genérico o un método genérico, esta propiedad siempre devuelve false.

Se aplica a

Produto Versións
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

Consulte también