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.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDual) System.Runtime.InteropServices.ComVisible(true)

Provides support for classes. This class is the root of the object hierarchy.

Classes derived from can override the following methods of the class:

- Enables comparisons between objects.
- Performs clean up operations before an object is automatically reclaimed.
- Generates a number corresponding to the value of the object (to support the use of a hashtable).
- Manufactures a human-readable text string that describes an instance of the class.
- Constructor

  Constructs a new instance of the class.

  This constructor is called by constructors in derived classes, but it can also be used to directly create an instance of the class. This might be useful, for example, if you need to obtain a reference to an object so that you can synchronize on it, as might be the case when using the C# statement.

  0
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Runtime.ConstrainedExecution.ReliabilityContract(System.Runtime.ConstrainedExecution.Consistency.WillNotCorruptState, System.Runtime.ConstrainedExecution.Cer.MayFail)
- Method
  System.Boolean `` The to compare with the current instance.

  Determines whether the specified is equal to the current instance.

  if is equal to the current instance; otherwise, .

  The statements listed below are required to be true for all implementations of the method. In the list, x, y, and z represent non-null object references.

  x.Equals(x) returns .
  x.Equals(y) returns the same value as y.Equals(x).
  If (x.Equals(y) && y.Equals(z)) returns , then x.Equals(z) returns .
  Successive invocations of x.Equals(y) return the same value as long as the objects referenced by x and y are not modified.
  x.Equals() returns for non-null x.

  See for additional required behaviors pertaining to the method.

  Implementations of should not throw exceptions.

  The method tests for , which means that returns if the specified instance of and the current instance are the same instance; otherwise, it returns .

  An implementation of the method is shown in the following C# code:

  public virtual bool Equals(Object obj) {

  return this == obj;

  }

  For some kinds of objects, it is desirable to have test for instead of referential equality. Such implementations of return true if the two objects have the same "value", even if they are not the same instance. The definition of what constitutes an object's "value" is up to the implementer of the type, but it is typically some or all of the data stored in the instance variables of the object. For example, the value of a is based on the characters of the string; the method of the class returns for any two string instances that contain exactly the same characters in the same order.

  When the method of a base class provides value equality, an override of in a class derived from that base class should invoke the inherited implementation of .

  All implementations of are required to ensure that for any two object references and , if , then .

  If your programming language supports operator overloading, and if you choose to overload the equality operator for a given type, that type should override the method. Such implementations of the method should return the same results as the equality operator. Following this guideline will help ensure that class library code using (such as and

  ) behaves in a manner that is consistent with the way the equality operator is used by application code.

  If you are implementing a value type, you should follow these guidelines:

  Consider overriding to gain increased performance over that provided by the default implementation of on .
  If you override

  and the language supports operator overloading, you should overload the equality operator for your value type.

  For reference types, the guidelines are as follows:

  Consider overriding on a reference type if the semantics of the type are based on the fact that the type represents some value(s). For example, reference types such as Point and BigNumber should override .
  Most reference types should not overload the equality operator, even if they override

  . However, if you are implementing a reference type that is intended to have value semantics, such as a complex number type, you should override the equality operator.

  If you implement on a given type, you should override on that type.

  The method is called by methods in collections classes that perform search operations, including the method and the method.

  The following example contains two calls to the default implementation of .

  `using System; class MyClass { static void Main() { Object obj1 = new Object(); Object obj2 = new Object(); Console.WriteLine(obj1.Equals(obj2)); obj1 = obj2; Console.WriteLine(obj1.Equals(obj2)); } }`

  The output is

  False

  True

  The following example shows a class that overrides the method to provide value equality and a class , which is derived from . Because Point's override of is the first in the inheritance chain to introduce value equality, the method of the base class (which is inherited from and checks for referential equality) is not invoked. However, invokes because implements in a manner that provides value equality.

  `using System; public class Point: object { int x, y; public override bool Equals(Object obj) { //Check for null and compare run-time types. if (obj == null || GetType() != obj.GetType()) return false; Point p = (Point)obj; return (x == p.x) && (y == p.y); } public override int GetHashCode() { return x ^ y; } } class Point3D: Point { int z; public override bool Equals(Object obj) { return base.Equals(obj) && z == ((Point3D)obj).z; } public override int GetHashCode() { return base.GetHashCode() ^ z; } }`

  The method checks that the argument is non-null and that it references an instance of the same type as this object. If either of those checks fail, the method returns false. The method uses to determine whether the run-time types of the two objects are identical. (Note that is not used here because it returns the static type.) If instead the method had used a check of the form is Point , the check would return true in cases where is an instance of a subclass of , even though and the current instance are not of the same runtime type. Having verified that both objects are of the same type, the method casts to type and returns the result of comparing the instance variables of the two objects.

  In , the inherited method is invoked before anything else is done; the inherited method checks to see that is non-null, that is an instance of the same class as this object, and that the inherited instance variables match. Only when the inherited returns true does the method compare the instance variables introduced in the subclass. Specifically, the cast to is not executed unless has been determined to be of type or a subclass of .

  In the previous example, operator == (the equality operator) is used to compare the individual instance variables. In some cases, it is appropriate to use the method to compare instance variables in an implementation, as shown in the following example:

  `using System; class Rectangle { Point a, b; public override bool Equals(Object obj) { if (obj == null || GetType() != obj.GetType()) return false; Rectangle r = (Rectangle)obj; //Use Equals to compare instance variables return a.Equals(r.a) && b.Equals(r.b); } public override int GetHashCode() { return a.GetHashCode() ^ b.GetHashCode(); } }`

  In some languages, such as C#, operator overloading is supported. When a type overloads operator ==, it should also override the method to provide the same functionality. This is typically accomplished by writing the method in terms of the overloaded operator ==. For example:

  `using System; public struct Complex { double re, im; public override bool Equals(Object obj) { return obj is Complex && this == (Complex)obj; } public override int GetHashCode() { return re.GetHashCode() ^ im.GetHashCode(); } public static bool operator ==(Complex x, Complex y) { return x.re == y.re && x.im == y.im; } public static bool operator !=(Complex x, Complex y) { return !(x == y); } }`

  Because Complex is a C# struct (a value type), it is known that there will be no subclasses of . Therefore, the method need not compare the GetType() results for each object, but can instead use the operator to check the type of the parameter.

  0
  1.0.5000.0
  2.0.0.0
  4.0.0.0
- Method
  System.Boolean `` `` To be added. To be added.

  Determines whether two object references are equal.

  if one or more of the following statements is true:

  and refer to the same object,
  and are both null references,
  is not and .Equals( ) returns true;

  otherwise returns .

  This static method checks for null references before it calls .Equals( ) and returns false if either or is null. If the Equals(object ) implementation throws an exception, this method throws an exception.

  The following example demonstrates the method.

  `using System; public class MyClass { public static void Main() { string s1 = "Tom"; string s2 = "Carol"; Console.WriteLine("Object.Equals(\"{0}\", \"{1}\") => {2}", s1, s2, Object.Equals(s1, s2)); s1 = "Tom"; s2 = "Tom"; Console.WriteLine("Object.Equals(\"{0}\", \"{1}\") => {2}", s1, s2, Object.Equals(s1, s2)); s1 = null; s2 = "Tom"; Console.WriteLine("Object.Equals(null, \"{1}\") => {2}", s1, s2, Object.Equals(s1, s2)); s1 = "Carol"; s2 = null; Console.WriteLine("Object.Equals(\"{0}\", null) => {2}", s1, s2, Object.Equals(s1, s2)); s1 = null; s2 = null; Console.WriteLine("Object.Equals(null, null) => {2}", s1, s2, Object.Equals(s1, s2)); } }`

  The output is

  Object.Equals("Tom", "Carol") => False

  Object.Equals("Tom", "Tom") => True

  Object.Equals(null, "Tom") => False

  Object.Equals("Carol", null) => False

  Object.Equals(null, null) => True

  0
  1.0.5000.0
  2.0.0.0
  4.0.0.0
- Method
  System.Void

  Allows a to perform cleanup operations before the memory allocated for the is automatically reclaimed.

  During execution, is automatically called after an object becomes inaccessible, unless the object has been exempted from finalization by a call to . During shutdown of an application domain, is automatically called on objects that are not exempt from finalization, even those that are still accessible. is automatically called only once on a given instance, unless the object is re-registered using a mechanism such as and has not been subsequently called.

  Conforming implementations of the CLI are required to make every effort to ensure that for every object that has not been exempted from finalization, the method is called after the object becomes inaccessible. However, there might be some circumstances under which is not called. Conforming CLI implementations are required to explicitly specify the conditions under which is not guaranteed to be called. For example, might not be guaranteed to be called in the event of equipment failure, power failure, or other catastrophic system failures.

  In addition to and , conforming implementations of the CLI are allowed to provide other mechanisms that affect the behavior of . Any mechanisms provided are required to be specified by the CLI implementation.

  The order in which the methods of two objects are run is unspecified, even if one object refers to the other.

  The thread on which is run is unspecified.

  Every implementation of in a derived type is required to call its base type's implementation of . This is the only case in which application code calls .

  The implementation does nothing.

  A type should implement when it uses unmanaged resources such as file handles or database connections that must be released when the managed object that uses them is reclaimed. Because methods can be invoked in any order (including from multiple threads), synchronization can be necessary if the method can interact with other objects, whether accessible or not. Furthermore, since the order in which is called is unspecified, implementers of (or of destructors implemented through overriding Finalize) must take care to correctly handle references to other objects, as their

  method might already have been invoked. In general, referenced objects should not be considered valid during finalization.

  See the interface for an alternate means of disposing of resources.

  For C# developers: Destructors are the C# mechanism for performing cleanup operations. Destructors provide appropriate safeguards, such as automatically calling the base type's destructor. In C# code, cannot be called or overridden.

  0
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Runtime.ConstrainedExecution.ReliabilityContract(System.Runtime.ConstrainedExecution.Consistency.WillNotCorruptState, System.Runtime.ConstrainedExecution.Cer.Success)
- Method
  System.Int32

  Generates a hash code for the current instance.

  A containing the hash code for the current instance.

  serves as a hash function for a specific type. A hash function is used to quickly generate a number (a hash code) corresponding to the value of an object. Hash functions are used with . A good hash function algorithm rarely generates hash codes that collide. For more information about hash functions, see , Vol. 3, by Donald E. Knuth.

  All implementations of are required to ensure that for any two object references x and y, if x.Equals(y) == true, then x.GetHashCode() == y.GetHashCode().

  Hash codes generated by need not be unique.

  Implementations of are not permitted to throw exceptions.

  The implementation attempts to produce a unique hash code for every object, but the hash codes generated by this method are not guaranteed to be unique. Therefore, can generate the same hash code for two different instances.

  It is recommended (but not required) that types overriding also override . Hashtables cannot be relied on to work correctly if this recommendation is not followed.

  Use this method to obtain the hash code of an object. Hash codes should not be persisted (i.e. in a database or file) as they are allowed to change from run to run.

  In some cases, is implemented to simply return an integer value. The following example illustrates an implementation of , which returns an integer value:

  `using System; public struct Int32 { int value; //other methods... public override int GetHashCode() { return value; } }`

  Frequently, a type has multiple data members that can participate in generating the hash code. One way to generate a hash code is to combine these fields using an xor (exclusive or) operation, as shown in the following example:

  `using System; public struct Point { int x; int y; //other methods public override int GetHashCode() { return x ^ y; } }`

  The following example illustrates another case where the type's fields are combined using xor (exclusive or) to generate the hash code. Notice that in this example, the fields represent user-defined types, each of which implements (and should implement as well):

  `using System; public class SomeType { public override int GetHashCode() { return 0; } } public class AnotherType { public override int GetHashCode() { return 1; } } public class LastType { public override int GetHashCode() { return 2; } } public class MyClass { SomeType a = new SomeType(); AnotherType b = new AnotherType(); LastType c = new LastType(); public override int GetHashCode () { return a.GetHashCode() ^ b.GetHashCode() ^ c.GetHashCode(); } }`

  Avoid implementing in a manner that results in circular references. In other words, if AClass.GetHashCode calls BClass.GetHashCode, it should not be the case that BClass.GetHashCode calls AClass.GetHashCode.

  In some cases, the data member of the class in which you are implementing is bigger than a . In such cases, you could combine the high order bits of the value with the low order bits using an XOR operation, as shown in the following example:

  `using System; public struct Int64 { long value; //other methods... public override int GetHashCode() { return ((int)value ^ (int)(value >> 32)); } }` 0 1.0.5000.0 2.0.0.0 4.0.0.0
- Method
  System.Type

  Gets the type of the current instance.

  The instance of that represents the run-time type (the exact type) of the current instance.

  For two objects x and y that have identical run-time types, (x.GetType(),y.GetType()) returns .

  The following example demonstrates the fact that returns the run-time type of the current instance:

  `using System; public class MyBaseClass: Object { } public class MyDerivedClass: MyBaseClass { } public class Test { public static void Main() { MyBaseClass myBase = new MyBaseClass(); MyDerivedClass myDerived = new MyDerivedClass(); object o = myDerived; MyBaseClass b = myDerived; Console.WriteLine("mybase: Type is {0}", myBase.GetType()); Console.WriteLine("myDerived: Type is {0}", myDerived.GetType()); Console.WriteLine("object o = myDerived: Type is {0}", o.GetType()); Console.WriteLine("MyBaseClass b = myDerived: Type is {0}", b.GetType()); } }`

  The output is

  mybase: Type is MyBaseClass

  myDerived: Type is MyDerivedClass

  object o = myDerived: Type is MyDerivedClass

  MyBaseClass b = myDerived: Type is MyDerivedClass

  0
  1.0.5000.0
  2.0.0.0
  4.0.0.0
- Method
  System.Object

  Creates a shallow copy of the current instance.

  A shallow copy of the current instance. The run-time type (the exact type) of the returned object is the same as the run-time type of the object that was copied.

  creates a new instance of the same type as the current instance and then copies each of the object's non-static fields in a manner that depends on whether the field is a value type or a reference type. If the field is a value type, a bit-by-bit copy of all the field's bits is performed. If the field is a reference type, only the reference is copied. The algorithm for performing a shallow copy is as follows (in pseudo-code):

  for each instance field f in this instance

  if (f is a value type)

  bitwise copy the field

  if (f is a reference type)

  copy the reference

  end for loop

  This mechanism is referred to as a shallow copy because it copies rather than clones the non-static fields.

  Because implements the above algorithm, for any object, a, the following statements are required to be true:

  a.MemberwiseClone() is not identical to a.

  a.MemberwiseClone().GetType() is identical to a.GetType().

  does not call any of the type's constructors.

  If has been overridden, a.MemberwiseClone().Equals(a) might return .

  For an alternate copying mechanism, see .

  is protected (rather than public) to ensure that from verifiable code it is only possible to clone objects of the same class as the one performing the operation (or one of its subclasses). Although cloning an object does not directly open security holes, it does allow an object to be created without running any of its constructors. Since these constructors might establish important invariants, objects created by cloning might not have these invariants established, and this can lead to incorrect program behavior. For example, a constructor might add the new object to a linked list of all objects of this class, and cloning the object would not add the new object to that list -- thus operations that relied on the list to locate all instances would fail to notice the cloned object. By making the method protected, only objects of the same class (or a subclass) can produce a clone and implementers of those classes are (presumably) aware of the appropriate invariants and can arrange for them to be true without necessarily calling a constructor.

  The following example shows a class called as well as a representation of the instance of returned by .

  `using System; class MyBaseClass { public static string CompanyName = "My Company"; public int age; public string name; } class MyDerivedClass: MyBaseClass { static void Main() { //Create an instance of MyDerivedClass //and assign values to its fields. MyDerivedClass m1 = new MyDerivedClass(); m1.age = 42; m1.name = "Sam"; //Do a shallow copy of m1 //and assign it to m2. MyDerivedClass m2 = (MyDerivedClass) m1.MemberwiseClone(); } }`

  A graphical representation of m1 and m2 might look like this

  `+---------------+ | 42 | m1 +---------------+ | +---------|-----------------> "Sam" +---------------+ /|\ | +---------------+ | | 42 | | m2 +---------------+ | | +--------|---------------------| +---------------+` 0 1.0.5000.0 2.0.0.0 4.0.0.0
- Method
  System.Boolean `` `` To be added. To be added.

  Determines whether two object references are identical.

  if and refer to the same object or are both null references; otherwise, .

  This static method provides a way to compare two objects for reference equality. It does not call any user-defined code, including overrides of .

  `using System; class MyClass { static void Main() { object o = null; object p = null; object q = new Object(); Console.WriteLine(Object.ReferenceEquals(o, p)); p = q; Console.WriteLine(Object.ReferenceEquals(p, q)); Console.WriteLine(Object.ReferenceEquals(o, p)); } }`

  The output is

  True

  True

  False

  0
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Runtime.ConstrainedExecution.ReliabilityContract(System.Runtime.ConstrainedExecution.Consistency.WillNotCorruptState, System.Runtime.ConstrainedExecution.Cer.Success)
- Method
  System.String

  Creates and returns a representation of the current instance.

  A representation of the current instance.

  returns a string whose content is intended to be understood by humans. Where the object contains culture-sensitive data, the string representation returned by takes into account the current system culture. For example, for an instance of the class whose value is zero, the implementation of might return "0.00" or "0,00" depending on the current UI culture. Although there are no exact requirements for the format of the returned string, it should as much as possible reflect the value of the object as perceived by the user.

  is equivalent to calling to obtain the object for the current instance and then returning the result of calling the implementation for that type. The value returned includes the full name of the type.

  It is recommended, but not required, that be overridden in a derived class to return values that are meaningful for that type. For example, the base data types, such as , implement so that it returns the string form of the value the object represents.

  Subclasses that require more control over the formatting of strings than provides should implement , whose method uses the culture of the current thread.

  The following example outputs the textual description of the value of an object of type to the console.

  `using System; class MyClass { static void Main() { object o = new object(); Console.WriteLine (o.ToString()); } }`

  The output is

  System.Object

  0
  1.0.5000.0
  2.0.0.0
  4.0.0.0
0