You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: xml/System/ValueType.xml
+5Lines changed: 5 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -66,11 +66,13 @@
66
66
Aside from serving as the base class for value types in the .NET Framework, the <xref:System.ValueType> structure is generally not used directly in code. However, it can be used as a parameter in method calls to restrict possible arguments to value types instead of all objects, or to permit a method to handle a number of different value types. The following example illustrates how <xref:System.ValueType> prevents reference types from being passed to methods. It defines a class named `Utility` that contains four methods: `IsNumeric`, which indicates whether its argument is a number; `IsInteger`, which indicates whether its argument is an integer; `IsFloat`, which indicates whether its argument is a floating-point number; and `Compare`, which indicates the relationship between two numeric values. In each case, the method parameters are of type <xref:System.ValueType>, and reference types are prevented from being passed to the methods.
Value types defined by the `struct` keyword in C# and the `Structure`...`End Structure` construct in Visual Basic typically override the <xref:System.ValueType.ToString%2A?displayProperty=nameWithType> method to provide a more meaningful string representation of the value type. The following example illustrates the difference. It defines two value types, `EmployeeA` and `EmployeeB`, creates an instance of each, and calls its `ToString` method. Because the `EmployeeA` structure does not override the <xref:System.ValueType.ToString%2A?displayProperty=nameWithType> method, it displays only the fully qualified type name. The `EmployeeB.ToString` method, on the other hand, provides meaningful information about the object.
Note that, although enumeration types are also value types, they derive from the <xref:System.Enum> class, which overrides <xref:System.ValueType.ToString%2A?displayProperty=nameWithType>.
0 commit comments