Sobes.tech
Junior — Middle

Kas saaksite nimetada Object klassi objektiis saadaolevad peamised meetodid?

sobes.tech AI

Vastus AI-lt

In C#, the Object class is the base for all types and provides several key methods:

  • Equals(object obj) — checks if the current object is equal to another.
  • GetHashCode() — returns the hash code of the object, used in collections.
  • ToString() — returns the string representation of the object.
  • GetType() — returns the type of the current instance.
  • MemberwiseClone() — creates a shallow copy of the object (protected method).
  • Finalize() — called before garbage collection to clean up resources (usually via destructor).

Example usage:

object obj = new object();
Console.WriteLine(obj.ToString());
Console.WriteLine(obj.GetHashCode());
Console.WriteLine(obj.GetType());