String.ToString Method

Definition

Convierte el valor de la instancia en un objeto String.Converts the value of this instance to a String.

Overloads

ToString(IFormatProvider)

Devuelve la instancia de String; no se efectúa una conversión real.Returns this instance of String; no actual conversion is performed.

ToString()

Devuelve la instancia de String; no se efectúa una conversión real.Returns this instance of String; no actual conversion is performed.

ToString(IFormatProvider)

Devuelve la instancia de String; no se efectúa una conversión real.Returns this instance of String; no actual conversion is performed.

public:
 virtual System::String ^ ToString(IFormatProvider ^ provider);
public string ToString (IFormatProvider provider);
override this.ToString : IFormatProvider -> string
Public Function ToString (provider As IFormatProvider) As String

Parameters

provider
IFormatProvider

(Reservado) Un objeto que aporta información de formato específica de la referencia cultural.(Reserved) An object that supplies culture-specific formatting information.

Returns

String

Cadena actual.The current string.

Implements

Remarks

provider está reservada y no participa actualmente en esta operación.provider is reserved, and does not currently participate in this operation.

Dado que este método simplemente devuelve la cadena actual sin modificar, no es necesario llamarlo directamente.Because this method simply returns the current string unchanged, there is no need to call it directly.

ToString()

Devuelve la instancia de String; no se efectúa una conversión real.Returns this instance of String; no actual conversion is performed.

public:
 override System::String ^ ToString();
public override string ToString ();
override this.ToString : unit -> string
Public Overrides Function ToString () As String

Returns

String

Cadena actual.The current string.

Examples

En el siguiente ejemplo se muestra el método ToString. Tenga en cuenta que en el ejemplo no se llama explícitamente al método ToString.The following example demonstrates the ToString method.Note that the example does not explicitly call the ToString method. En su lugar, la característica de formato compuesto llama implícitamente al método.Instead, the method is called implicitly by the composite formatting feature.

using namespace System;
int main()
{
   String^ str1 = "123";
   String^ str2 = "abc";
   Console::WriteLine( "Original str1: {0}", str1 );
   Console::WriteLine( "Original str2: {0}", str2 );
   Console::WriteLine( "str1 same as str2?: {0}", Object::ReferenceEquals( str1, str2 ) );
   str2 = str1;
   Console::WriteLine();
   Console::WriteLine( "New str2:      {0}", str2 );
   Console::WriteLine( "str1 same as str2?: {0}", Object::ReferenceEquals( str1, str2 ) );
}

/*
This code produces the following output:
Original str1: 123
Original str2: abc
str1 same as str2?: False

New str2:      123
str1 same as str2?: True
*/
using System;

class stringToString {
    public static void Main() {
    String str1 = "123";
    String str2 = "abc";

    Console.WriteLine("Original str1: {0}", str1);
    Console.WriteLine("Original str2: {0}", str2);
    Console.WriteLine("str1 same as str2?: {0}", Object.ReferenceEquals(str1, str2));

    str2 = str1.ToString();
    Console.WriteLine();
    Console.WriteLine("New str2:      {0}", str2);
    Console.WriteLine("str1 same as str2?: {0}", Object.ReferenceEquals(str1, str2));
    }
}
/*
This code produces the following output:
Original str1: 123
Original str2: abc
str1 same as str2?: False

New str2:      123
str1 same as str2?: True
*/
 _

Class stringToString
   
   Public Shared Sub Main()
      Dim str1 As [String] = "123"
      Dim str2 As [String] = "abc"
      
      Console.WriteLine("Original str1: {0}", str1)
      Console.WriteLine("Original str2: {0}", str2)
      Console.WriteLine("str1 same as str2?: {0}", [Object].ReferenceEquals(str1, str2))
      
      str2 = str1.ToString()
      Console.WriteLine()
      Console.WriteLine("New str2:      {0}", str2)
      Console.WriteLine("str1 same as str2?: {0}", [Object].ReferenceEquals(str1, str2))
   End Sub
End Class
'
'This code produces the following output:
'Original str1: 123
'Original str2: abc
'str1 same as str2?: False
'
'New str2:      123
'str1 same as str2?: True
'

Remarks

Dado que este método simplemente devuelve la cadena actual sin modificar, no es necesario llamarlo directamente.Because this method simply returns the current string unchanged, there is no need to call it directly. Normalmente se llama implícitamente en una operación de formato compuesto, como se muestra en el ejemplo.It is usually called implicitly in a composite formatting operation, as the example shows.

See also

Applies to