¿Le resultó útil esta página?
Sus comentarios sobre este contenido son muy importantes. Háganos saber su opinión.
¿Tiene comentarios adicionales?
Caracteres restantes: 1500
ToString (Método) (Boolean, IFormatProvider)

Convert.ToString (Método) (Boolean, IFormatProvider)

Actualización: noviembre 2007

Convierte el valor booleano especificado en la representación de tipo String equivalente.

Espacio de nombres:  System
Ensamblado:  mscorlib (en mscorlib.dll)

public static string ToString(
	bool value,
	IFormatProvider provider
)
public static String ToString(
	boolean value,
	IFormatProvider provider
)
public static function ToString(
	value : boolean, 
	provider : IFormatProvider
) : String

Parámetros

value
Tipo: System.Boolean
Valor booleano.
provider
Tipo: System.IFormatProvider
(Reservado) Instancia de una implementación de la interfaz IFormatProvider.

Valor devuelto

Tipo: System.String
String que equivale al valor de value.

Esta implementación es idéntica al método Boolean.ToString.

En el siguiente ejemplo de código se convierte un valor Boolean en un tipo String mediante el método ToString, utilizando un objeto IFormatProvider que muestra el tipo del proveedor de formato para el que se ha realizado la llamada. En el ejemplo se muestra que no se hace referencia al objeto IFormatProvider.

// Example of Convert.ToString( non-numeric types, IFormatProvider ).
using System;
using System.Globalization;

// An instance of this class can be passed to methods that require 
// an IFormatProvider.
public class DummyProvider : IFormatProvider
{
    // Normally, GetFormat returns an object of the requested type
    // (usually itself) if it is able; otherwise, it returns Nothing. 
    public object GetFormat( Type argType )
    {
        // Here, the type of argType is displayed, and GetFormat
        // always returns Nothing.
        Console.Write( "{0,-40}", argType.ToString( ) );
        return null;
    }
}

class ConvertNonNumericProviderDemo
{
    static void Main( )
    {
        // Create an instance of the IFormatProvider.
        DummyProvider provider = new DummyProvider( );
        string converted;

        // Convert these values using DummyProvider.
        int      Int32A     = -252645135;
        double   DoubleA    = 61680.3855;
        object   ObjDouble  = (object)( -98765.4321 );
        DateTime DayTimeA   = new DateTime( 2001, 9, 11, 13, 45, 0 );

        bool     BoolA      = true;
        string   StringA    = "Qwerty";
        char     CharA      = '$';
        TimeSpan TSpanA     = new TimeSpan( 0, 18, 0 );
        object   ObjOther   = (object)provider;

        Console.WriteLine( "This example of " +
            "Convert.ToString( non-numeric, IFormatProvider ) \n" +
            "generates the following output. The provider type, " +
            "argument type, \nand argument value are displayed." );
        Console.WriteLine( "\nNote: The IFormatProvider object is " +
            "not called for Boolean, String, \nChar, TimeSpan, " +
            "and non-numeric Object." );

        // The format provider is called for these conversions.
        Console.WriteLine( );
        converted = Convert.ToString( Int32A, provider );
        Console.WriteLine( "int      {0}", converted );
        converted = Convert.ToString( DoubleA, provider );
        Console.WriteLine( "double   {0}", converted );
        converted = Convert.ToString( ObjDouble, provider );
        Console.WriteLine( "object   {0}", converted );
        converted = Convert.ToString( DayTimeA, provider );
        Console.WriteLine( "DateTime {0}", converted );

        // The format provider is not called for these conversions.
        Console.WriteLine( );
        converted = Convert.ToString( BoolA, provider );
        Console.WriteLine( "bool     {0}", converted );
        converted = Convert.ToString( StringA, provider );
        Console.WriteLine( "string   {0}", converted );
        converted = Convert.ToString( CharA, provider );
        Console.WriteLine( "char     {0}", converted );
        converted = Convert.ToString( TSpanA, provider );
        Console.WriteLine( "TimeSpan {0}", converted );
        converted = Convert.ToString( ObjOther, provider );
        Console.WriteLine( "object   {0}", converted );
    }
}

/*
This example of Convert.ToString( non-numeric, IFormatProvider )
generates the following output. The provider type, argument type,
and argument value are displayed.

Note: The IFormatProvider object is not called for Boolean, String,
Char, TimeSpan, and non-numeric Object.

System.Globalization.NumberFormatInfo   int      -252645135
System.Globalization.NumberFormatInfo   double   61680.3855
System.Globalization.NumberFormatInfo   object   -98765.4321
System.Globalization.DateTimeFormatInfo DateTime 9/11/2001 1:45:00 PM

bool     True
string   Qwerty
char     $
TimeSpan 00:18:00
object   DummyProvider

*/ 


// Example of Convert.ToString( non-numeric types, IFormatProvider ).
import System.* ;
import System.Globalization.* ;

// An instance of this class can be passed to methods that require 
// an IFormatProvider.
public class DummyProvider implements IFormatProvider
{
    // Normally, GetFormat returns an object of the requested type
    // (usually itself) if it is able; otherwise, it returns Nothing. 
    public Object GetFormat(Type argType) 
    {
        // Here, the type of argType is displayed, and GetFormat
        // always returns Nothing.
        Console.Write("{0,-40}", argType.ToString());
        return null ;
    } //GetFormat
} //DummyProvider

class ConvertNonNumericProviderDemo
{   
    public static void main(String[] args)
    {  
        // Create an instance of the IFormatProvider.
        DummyProvider provider =  new DummyProvider();
        String converted;

        // Convert these values using DummyProvider.
        int int32A = -252645135;
        double doubleA = 61680.3855;
        Object objDouble = (System.Double)(-98765.4321);
        DateTime dayTimeA =  new DateTime(2001, 9, 11, 13, 45, 0);

        boolean boolA = true;
        String stringA = "Qwerty";
        char charA = '$';
        TimeSpan tSpanA =  new TimeSpan(0, 18, 0);
        Object objOther = (Object)(provider);

        Console.WriteLine(("This example of "
            + "Convert.ToString( non-numeric, IFormatProvider ) \n" 
            + "generates the following output. The provider type, " 
            + "argument type, \nand argument value are displayed."));
        Console.WriteLine(("\nNote: The IFormatProvider object is "
            + "not called for Boolean, String, \nChar, TimeSpan, " 
            + "and non-numeric Object."));

        // The format provider is called for these conversions.
        Console.WriteLine();
        converted = Convert.ToString(int32A, provider);
        Console.WriteLine("int      {0}", converted);
        converted = Convert.ToString(doubleA, provider);
        Console.WriteLine("double   {0}", converted);
        converted = Convert.ToString(objDouble, provider);
        Console.WriteLine("object   {0}", converted);
        converted = Convert.ToString(dayTimeA, provider);
        Console.WriteLine("DateTime {0}", converted);

        // The format provider is not called for these conversions.
        Console.WriteLine();
        converted = Convert.ToString(boolA, provider);
        Console.WriteLine("bool     {0}", converted);
        converted = Convert.ToString(stringA, provider);
        Console.WriteLine("string   {0}", converted);
        converted = Convert.ToString(charA, provider);
        Console.WriteLine("char     {0}", converted);
        converted = Convert.ToString(tSpanA, provider);
        Console.WriteLine("TimeSpan {0}", converted);
        converted = Convert.ToString(objOther, provider);
        Console.WriteLine("object   {0}", converted);
    } //main
} //ConvertNonNumericProviderDemo

/*
This example of Convert.ToString( non-numeric, IFormatProvider )
generates the following output. The provider type, argument type,
and argument value are displayed.

Note: The IFormatProvider object is not called for Boolean, String,
Char, TimeSpan, and non-numeric Object.

System.Globalization.NumberFormatInfo   int      -252645135
System.Globalization.NumberFormatInfo   double   61680.3855
System.Globalization.NumberFormatInfo   object   -98765.4321
System.Globalization.DateTimeFormatInfo DateTime 9/11/2001 1:45:00 PM

bool     True
string   Qwerty
char     $
TimeSpan 00:18:00
object   DummyProvider@33c0d9d

*/


Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile para Smartphone, Windows Mobile para Pocket PC, Xbox 360

.NET Framework y .NET Compact Framework no admiten todas las versiones de cada plataforma. Para obtener una lista de las versiones compatibles, vea Requisitos de sistema de .NET Framework.

.NET Framework

Compatible con: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Compatible con: 3.5, 2.0

XNA Framework

Compatible con: 2.0, 1.0

Adiciones de comunidad

AGREGAR
Mostrar:
© 2015 Microsoft