Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# keyword similar to "this" but for current class type?

Is there a keyword to refer to the current class type similar to how this refers to the current instance?

My intention is to avoid having to type the full class name when refering to static members or Enums but I want to prefex it with something like "this" for readability like I do for instance members. The reason being some of the class names are pretty huge and cause excessive wrapping.

like image 597
Monstieur Avatar asked Nov 04 '25 17:11

Monstieur


2 Answers

I don't think there's a keyword, but maybe as good:

this.GetType();

GetType is one of the few methods implemented by System.Object.

like image 169
McGarnagle Avatar answered Nov 06 '25 08:11

McGarnagle


If you include the namespace with using, you won't indeed to enter the full path.

You can alias the class names with using, for instance:

using ClassA = Really.Deep.Class.In.Namepsace.For.SomePurpose.ClassA;
like image 38
Candide Avatar answered Nov 06 '25 07:11

Candide



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!