I hate to see the name of the class used as a string parameter like "FileDownloader" in the code, and I would like to use something like this FileDownloader.Name(), where FileDownloader is name of the class.
Only problem is that I can't find out how to do that without instantiating object or creating a static method...
Is there a way to get a class name in .net without having the object instance and without creating a static method that returns the name of the class?
In the same way that a static variable is associated with the class as a whole, so is a static method. In the same way that a static variable exists before an object of the class is instantiated, a static method can be called before instantiating an object.
Static Method Static methods are the methods in Java that can be called without creating an object of class.
In a Web API, a static method is one which is defined by an interface but can be called without instantiating an object of that type first.
A static method can be called directly from the class, without having to create an instance of the class. A static method can only access static variables; it cannot access instance variables. Since the static method refers to the class, the syntax to call or refer to a static method is: class name. method name.
Sure:
var name = typeof(FileDownloader).Name;
use the typeof operator:
typeof ( FileDownloader).Name
Try typeof(YourClass).name. This should expose the name of your class
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With