C# String Extension Overloading -


i want create extension class string overloads compareto method following:

    public static bool compareto(this string input, string comparevalue, bool ignorecase, bool removeextrawhitespaces)     {         if (removeextrawhitespaces)         {             input = input.removenullsandwhitespace(" ").trim();             comparevalue = comparevalue.removenullsandwhitespace(" ").trim();         }          return (string.compare(input, comparevalue, ignorecase)==0);     } 

however, when attempt use in normal class file such:

currentauthor.firstname.compareto(previousauthor.firstname, true, true) 

i getting compile error stating there no overload method compareto takes 3 parameters.

is idea possible?

i know in normal classes can overload until son comes home. whether static or non-static class.

is there exception extensions? have not worked them lot.

i've confirmed setting dotnetfiddle, see here: https://dotnetfiddle.net/62hhq8. you're trying should work fine.

as others have mentioned, think need make sure namespace extension method defined in included in every file you're trying call compareto extension method from.

otherwise, see nothing wrong , have confirmed method works.


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -