سؤال

I've searched and read MSDN, but I only found out how to add a instance method to a existed class.

Now, I want to add a static method to an existing class, like this:

String.myStaticMethod(....);

Can I do this? Is this not allowed in c#?

هل كانت مفيدة؟

المحلول

Extension methods only work for instance methods at this time, not static. There is no way to simulate adding static methods to an existing type defined in another assembly at this time in C#

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top