Export (0) Print
Expand All

UInt16.ToString Method

Converts the numeric value of this instance to its equivalent string representation.

The UInt16 type is not CLS-compliant. The CLS-compliant alternative type is Int32. Int16 can be used when the original value is less than half of UInt16.MaxValue. For more information about CLS compliance, see What is the Common Language Specification.

Overload List

Converts the numeric value of this instance to its equivalent string representation.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Overrides Public Function ToString() As String
[C#] public override string ToString();
[C++] public: String* ToString();
[JScript] public override function ToString() : String;

Converts the numeric value of this instance to its equivalent string representation using the specified culture-specific format information.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Overridable Function ToString(IFormatProvider) As String
[C#] public virtual string ToString(IFormatProvider);
[C++] public: virtual String* ToString(IFormatProvider*);
[JScript] public function ToString(IFormatProvider) : String;

Converts the numeric value of this instance to its equivalent string representation using the specified format.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Function ToString(String) As String
[C#] public string ToString(string);
[C++] public: String* ToString(String*);
[JScript] public function ToString(String) : String;

Converts the numeric value of this instance to its equivalent string representation using the specified format and culture-specific format information.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Overridable Function ToString(String, IFormatProvider) As String
[C#] public virtual string ToString(string, IFormatProvider);
[C++] public: virtual String* ToString(String*, IFormatProvider*);
[JScript] public function ToString(String, IFormatProvider) : String;

Example

[C#, C++, JScript] The following example demonstrates the ToString method.

[C#, C++, JScript] Note   This example shows how to use one of the overloaded versions of ToString. For other examples that might be available, see the individual overload topics.
[C#] 
public class Temperature : IFormattable {
    /// <summary>
    /// IFormattable.ToString implementation.
    /// </summary>
    public string ToString(string format, IFormatProvider provider) {
        if( format != null && format.Equals("F") ) {
            return String.Format("{0}'F", this.Value.ToString());
        }

        return m_value.ToString(format, provider);
    }

    // The value holder
    protected ushort m_value;

    public ushort Value {
        get {
            return m_value;
        }
        set {
            m_value = value;
        }
    }
}

[C++] 
public __gc class Temperature : public IFormattable {
    /// <summary>
    /// IFormattable.ToString implementation.
    /// </summary>
// The value holder
protected:
    short m_value;

public:
    String* ToString(String* format, IFormatProvider* provider) {
        if( format != NULL ) {
            if( format->Equals("F") ) {
                return String::Format("{0}'F", this->Value.ToString());
            }
            if( format->Equals("C") ) {
                return String::Format("{0}'C", this->Celsius.ToString());
            }
        }

        return m_value.ToString(format, provider);
    };

    __property short get_Value() {
        return m_value;
    };

    __property void set_Value( short value) {
        m_value = value;
    };

    __property short get_Celsius() {
        return (short)((m_value-32)/2);
    };

    __property void set_Celsius( short value) {
        m_value = (short)(value*2+32);
    };
};

[JScript] 
public class Temperature implements IFormattable {
    /// <summary>
    /// IFormattable.ToString implementation.
    /// </summary>
    public function ToString(format : String, provider : IFormatProvider) : String {
        if( format != null && format.Equals("F") ) {
            return String.Format("{0}'F", m_value.ToString());
        }

        return m_value.ToString(format, provider);
    }

    // The value holder
    protected var m_value : ushort;

    public function get Value() : ushort {
        return m_value;
            }
            
            public function set Value(value : ushort) {                        
        m_value = value;
    }
}

[Visual Basic] No example is available for Visual Basic. To view a C#, C++, or JScript example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

UInt16 Structure | UInt16 Members | System Namespace

Show:
© 2014 Microsoft