Hi Jesper and welcome to the forums!
this byte, what are you trying to do? The keyword 'this' doesn't belong there. Doesn't it work without?
Thanks Stefan..
I'm trying to reuse some code i have written in a PC application, and now the its the Netduino's time to do job.
I won't to make my call like this
if (testData.GetBitV1(0)) Console.WriteLine("BitV1: 0 is true");
With one parameter and not tow.
But with the Netduino program it seams that i can't write my extension method like this. To get it working i need tow parameter the source and the input value.
Console application to test.
using System;
using Win32TestFunc.Win32TestFunc;
namespace Win32TestFunc
{
class Program
{
static void Main()
{
const byte testData = 1;
if (testData.GetBitV1(0)) Console.WriteLine("BitV1: 0 is true"); // This solution i "need" but dose not work in the Micro framework
if (BitHelper.GetBitV2(testData, 0)) Console.WriteLine("BitV2: 0 is true"); // This solution is working in the Micro framework
Console.ReadLine();
}
}
}
The class
namespace Win32TestFunc
{
namespace Win32TestFunc
{
public static class BitHelper
{
public static bool GetBitV1(this byte b, int bitNumber)
{
return (b & (1 << bitNumber)) != 0;
}
public static bool GetBitV2(byte b, int bitNumber)
{
return (b & (1 << bitNumber)) != 0;
}
}
}
}