1

In my programming life in C#, whenever I create some variable (or object) in C# when I write .(dot) Intellisense for this variable (object) show me standard 4 methods.

For example I create empty class SomeClass

public class SomeClass
{

}

When I create object of this class, and call some methods, even if this class is empty intellisense show me this 4 methods.

static void Main(string[] args)
{
    SomeClass sc = new SomeClass();
       +---------------+
    sc.|Equals         |
       |GetHashCode    |
       |GetType        |
       |ToString       |
       +---------------+
}

Can anyone explain me why?

Thanks.

0

2 Answers 2

4

All classes inherit from System.Object - which contains those methods.

Sign up to request clarification or add additional context in comments.

Comments

3

Every class implicitly inherit from the Object class, from the System.Object namespace. Basically, it's the root of the type hierarchy.

Also, besides those 4 methods you pointed out, every object also inherit the Finalize method from Object.

Since your class inherits from Object, that statement would be valid :

object sc = new SomeClass();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.