I have the class:
class Program
{
static void Main(string[] args)
{
}
public static int SetFlag_Old(this int i, int flag, bool set = true)
{
return (set) ? i | flag : ((i & flag) != 0) ? (i - flag) : i;
}
}
And when I put this code into the main method above I do not get the option to call the extension method and I can't figure out why.
int i = 0;
i.
Even when I create a non-static method and insert that code I can't seem to call the extension methods. Am I missing something really simple?
The extension method has to be in a static class:
public static class IntExtensions
{
public static int SetFlag_Old(this int i, int flag, bool set = true)
{
return (set) ? i | flag : ((i & flag) != 0) ? (i - flag) : i;
}
}
http://msdn.microsoft.com/en-us/library/bb383977.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With