c# - Can you add extension methods that you call like static methods? -
according microsoft, "extension methods special kind of static method, called if instance methods on extended type".
is there way add extension method called if static method? or else has same effect?
edit: mean "called if static method on extended class". sorry ambiguity.
according microsoft, "extension methods special kind of static method, called if instance methods on extended type".
yes, extension methods static methods. can called in normal way static methods, extension instance methods on type "extend", , can called extension methods on null reference.
for example:
public static class extensions { public static bool isnullorempty(this string thestring) { return string.isnullorempty(thestring); } } // code elsewhere. string test = null; console.writeline(test.isnullorempty()); // valid code. console.writeline(extensions.isnullorempty(test)); // valid code.
edit:
is there way add extension method called if static method?
do mean want call, example, string.myextensionmethod()? in case, no, there no way that.
Comments
Post a Comment