The Object Class in C#


The Object class is the base class of all the classes in C#. It has the following methods on C#.

Sr.NoMethod & Description
1Equals(Object)
Determines whether the specified object is equal to the current object.
2Equals(Object,Object,
Determines whether the specified object instances are considered equal.
3Finalize()
Allows an object to try to free resources
4GetHashCode()
default hash function.
5GetType()
Type of the current instance.
6MemberwiseClone()
shallow copy of the current Object.
7ReferenceEquals(Object,Object)
Determines whether the specified Object instances are the same instance.
8ToString()
Returns a string that represents the current object.

Let us see an example how to create an object of a class in C#.

Example

 Live Demo

using System;
namespace MyApplication {
   class Demo {
      protected string name = "Website";
      protected void Display(string str) {
         Console.WriteLine("Tabs: " + str);
      }  
   }

   class Test : Demo {
      static void Main(string[] args) {
         Test t = new Test();
         Console.WriteLine("Details: " + t.name);
         t.Display("Product");
         t.Display("Services");
         t.Display("Tools");
         t.Display("Plugins");
      }
   }
}

Output

Details: Website
Tabs: Product
Tabs: Services
Tabs: Tools
Tabs: Plugins

Updated on: 22-Jun-2020

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements