Is there any possibilities to register a method in another class to a static
class in C#, so that i can call that class using the static
class name.
Example
public static class StaticClass
{
}
public static class Sample
{
public static string method1()
{return "";}
}
I want to call like this, StaticClass.method1()
.
First of all,IS IT VALID or Not? or Is there any possible way to do that?
First of all,IS IT VALID or Not?
Sure it's valid; just not the way you're portraying it.
Is there any possible way to do that?
One approach would be to build a method on StaticClass
called method1
. Maybe you want to encapsulate some default behavior:
public static class StaticClass
{
public static string method1()
{
// do what you need
Sample.method1();
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.