Skip to content

Commit 96847cb

Browse files
WilliamAntonRohmmairaw
authored andcommitted
updated for Try .NET (#3478)
1 parent b35654a commit 96847cb

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

xml/System/Object.xml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -994,7 +994,9 @@ and the <xref:System.IDisposable> interface. The <xref:System.IDisposable.Dispos
994994
> You may have reached this page by following the link from the member list of another type. That is because that type does not override <xref:System.Object.ToString%2A?displayProperty=nameWithType>. Instead, it inherits the functionality of the <xref:System.Object.ToString%2A?displayProperty=nameWithType> method.
995995
996996
Types frequently override the <xref:System.Object.ToString%2A?displayProperty=nameWithType> method to provide a more suitable string representation of a particular type. Types also frequently overload the <xref:System.Object.ToString%2A?displayProperty=nameWithType> method to provide support for format strings or culture-sensitive formatting.
997-
997+
998+
[!INCLUDE[interactive-note](~/includes/csharp-interactive-note-some.md)]
999+
9981000
In this section:
9991001
10001002
[The default Object.ToString() method](#Default)
@@ -1008,7 +1010,7 @@ and the <xref:System.IDisposable> interface. The <xref:System.IDisposable.Dispos
10081010
The default implementation of the <xref:System.Object.ToString%2A> method returns the fully qualified name of the type of the <xref:System.Object>, as the following example shows.
10091011
10101012
[!code-cpp[System.Object.ToString#1](~/samples/snippets/cpp/VS_Snippets_CLR_System/system.object.tostring/cpp/tostring1.cpp#1)]
1011-
[!code-csharp[System.Object.ToString#1](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.object.tostring/cs/tostring1.cs#1)]
1013+
[!code-csharp-interactive[System.Object.ToString#1](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.object.tostring/cs/tostring1.cs#1)]
10121014
[!code-vb[System.Object.ToString#1](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.object.tostring/vb/tostring1.vb#1)]
10131015
10141016
Because <xref:System.Object> is the base class of all reference types in the .NET Framework, this behavior is inherited by reference types that do not override the <xref:System.Object.ToString%2A> method. The following example illustrates this. It defines a class named `Object1` that accepts the default implementation of all <xref:System.Object> members. Its <xref:System.Object.ToString%2A> method returns the object's fully qualified type name.
@@ -1057,7 +1059,7 @@ and the <xref:System.IDisposable> interface. The <xref:System.IDisposable.Dispos
10571059
## Extending the Object.ToString method
10581060
Because a type inherits the default <xref:System.Object.ToString%2A?displayProperty=nameWithType> method, you may find its behavior undesirable and want to change it. This is particularly true of arrays and collection classes. While you may expect the `ToString` method of an array or collection class to display the values of its members, it instead displays the type fully qualified type name, as the following example shows.
10591061
1060-
[!code-csharp[System.Object.ToString#6](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.object.tostring/cs/array1.cs#6)]
1062+
[!code-csharp-interactive[System.Object.ToString#6](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.object.tostring/cs/array1.cs#6)]
10611063
[!code-vb[System.Object.ToString#6](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.object.tostring/vb/array1.vb#6)]
10621064
10631065
You have several options to produce the result string that you'd like.

0 commit comments

Comments
 (0)