BCL mscorlib [00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 ] 1.0.5000.0 2.0.0.0 4.0.0.0 All public static members of this type are safe for multithreaded operations. No instance members are guaranteed to be thread safe. System.Object System.Runtime.InteropServices.ComVisible(true)

In the following example, the number 3 is boxed as a , and () is called.

`using System; class Boxer { public static void Main() { Console.WriteLine("Value is {0}.", 3.ToString()); } }`

The output is

Value is 3.

overrides the virtual methods from with more appropriate implementations for value types. See also , which inherits from .

Data types are separated into value types and reference types. Value types are either stack-allocated or allocated inline in a structure. Reference types are heap-allocated. Both reference and value types are derived from the ultimate base class . In cases where it is necessary for a value type to behave like an object, a wrapper that makes the value type look like a reference object is allocated on the heap, and the value type's value is copied into it. The wrapper is marked so the system knows that it contains a value type. This process is known as boxing, and the reverse process is known as unboxing. Boxing and unboxing allow any type to be treated as an object.

Although is the implicit base class for value types, you cannot create a class that inherits from directly. Instead, individual compilers provide a language keyword or construct (such as struct in C# and Structure…End Structure in Visual Basic) to support the creation of value types.

Aside from serving as the base class for value types in the .NET Framework, the 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 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 , and reference types are prevented from being passed to the methods.

code reference: System.ValueType.Structure#1

The following example illustrates calls to the methods of the Utility class.

code reference: System.ValueType.Structure#2

Provides the base class for value types.

- Constructor
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  To be added.

  Initializes a new instance of the class.

  0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Boolean ``

  The method overrides and provides the default implementation of value equality for all value types in the .NET Framework.

  If none of the fields of the current instance and are reference types, the method performs a byte-by-byte comparison of the two objects in memory. Otherwise, it uses reflection to compare the corresponding fields of and this instance.

  Particularly if your value type contains fields that are reference types, you should override the method. This can improve performance and enable you to more closely represent the meaning of equality for the type.

  ## Notes for the wrt

  When you call the method on a wrt structure, it provides the default behavior for value types that don’t override . This is part of the support that the .NET Framework provides for the wrt (see .NET Framework Support for Windows Store Apps and Windows Runtime). wrt structures can’t override , even if they’re written with C# or Visual Basic, because they can’t have methods. (In addition, structures in the wrt itself don’t inherit .) However, they appear to have , , and methods when you use them in your C# or Visual Basic code, and the .NET Framework provides the default behavior for these methods.

  Indicates whether this instance and a specified object are equal.

  true if and this instance are the same type and represent the same value; otherwise, false.

  The object to compare with the current instance. 0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Int32

  The method applies to types derived from . One or more fields of the derived type is used to calculate the return value. If you call the derived type's GetHashCode method, the return value is not likely to be suitable for use as a key in a hash table. Additionally, if the value of one or more of those fields changes, the return value might become unsuitable for use as a key in a hash table. In either case, consider writing your own implementation of the method that more closely represents the concept of a hash code for the type.

  For more information, see , and .

  ## Notes for the wrt

  When you call the method on a wrt structure, it provides the default behavior for value types that don’t override . This is part of the support that the .NET Framework provides for the wrt (see .NET Framework Support for Windows Store Apps and Windows Runtime). wrt structures can’t override , even if they’re written with C# or Visual Basic, because they can’t have methods. (In addition, structures in the wrt itself don’t inherit .) However, they appear to have , , and methods when you use them in your C# or Visual Basic code, and the .NET Framework provides the default behavior for these methods.

  Returns the hash code for this instance.

  A 32-bit signed integer that is the hash code for this instance.

  0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.String

  When you call the method on a wrt structure, it provides the default behavior for value types that don’t override . This is part of the support that the .NET Framework provides for the wrt (see .NET Framework Support for Windows Store Apps and Windows Runtime). wrt structures can’t override , even if they’re written with C# or Visual Basic, because they can’t have methods. (In addition, structures in the wrt itself don’t inherit .) However, they appear to have , , and methods when you use them in your C# or Visual Basic code, and the .NET Framework provides the default behavior for these methods.

  Returns the fully qualified type name of this instance.

  A containing a fully qualified type name.

  0
0