Raghav55
Raghav55

Reputation: 3135

Difference between System.Object.GetType and System.Type.GetType

Is there any difference between System.Object.GetType() and System.Type.GetType().

Upvotes: 1

Views: 2658

Answers (4)

anishMarokey
anishMarokey

Reputation: 11397

System.Object.GetType() - Gets the Type of the current instance.

E.g:

var s ="sdf".GetType() // Gets System.String

System.Type.GetType() - Gets a Type object that represents the specified type

 Type type = Type.GetType("System.Int32");

Upvotes: 0

CodesInChaos
CodesInChaos

Reputation: 108800

System.Type is derived from System.Object. As such it inherits the parameterless instance method GetType() from System.Object. It will give you the type of the subclass of Type you got. And that's largely useless.

The static Type.GetType(string) function and it's overloads are something different entirely, despite having the same name. They get you the type with a specific name.

Upvotes: 3

V4Vendetta
V4Vendetta

Reputation: 38210

Object.GetType() gets the type of the current instance in which case it calls the Type.GetType for self.

Upvotes: 1

Akram Shahda
Akram Shahda

Reputation: 14781

Yes there is ..

Read about System.Object.GetType and System.Type.GetType.

Upvotes: 1

Related Questions