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

Popular posts from this blog

drupal - using views argument in the view tpl.php file -

php - Posting PHPBB Forum Thread/Post info in a website -

php - Add a blog by sending a mail to a certain emailadress -