Rect.ToString Method

Definition

Returns a string representation of the rectangle.

Overloads

ToString()

Returns a string representation of the rectangle.

ToString(IFormatProvider)

Returns a string representation of the rectangle by using the specified format provider.

ToString()

Returns a string representation of the rectangle.

C#
public override string ToString();

Returns

A string representation of the current rectangle. The string has the following form: "X,Y,Width,Height".

Examples

The following example shows how to use the ToString() method to get a string representation of a Rect structure.

C#
private string toStringExample()
{
    // Initialize new rectangle.
    Rect myRectangle = new Rect();

    // The Location property specifies the coordinates of the upper left-hand 
    // corner of the rectangle. 
    myRectangle.Location = new Point(10, 5);

    // Set the Size property of the rectangle with a width of 200
    // and a height of 50.
    myRectangle.Size = new Size(200, 50);

    // Get a string representation of a Rect structure.
    // rectString is equal to "10,5,200,50"	.
    string rectString = myRectangle.ToString();

    return rectString;
}

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 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
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

ToString(IFormatProvider)

Returns a string representation of the rectangle by using the specified format provider.

C#
public string ToString(IFormatProvider provider);

Parameters

provider
IFormatProvider

Culture-specific formatting information.

Returns

A string representation of the current rectangle that is determined by the specified format provider.

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 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
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10