Search code examples
c#xamarinxamarin.androidsmartcard

How to pass a interface as a parameter to a method C#


I am doing a project in Xamarin android and I'm following a java sample code to connect a smartcard reader (Acr1255u-j1) to android via Bluetooth , and I came acrros a method :

mManager.startScan(BluetoothTerminalManager.TERMINAL_TYPE_AMR220_C,
                   new BluetoothTerminalManager.TerminalScanCallback()
{
  @Override public void onScan(final CardTerminal terminal)
  {
    runOnUiThread(new Runnable() 
    {
      @Override public void run()
      {
        mTerminalAdapter.addTerminal(terminal);
      }
    });
  }
});

and the second parameter to the startscan method is a interface " BluetoothTerminalManager.TerminalScanCallback()" but when i try to convert it to c# it shows this error: erorr on c# code


Solution

  • You cannot do inline interface implementation in C#, you need to either have a class implementation for the interface or if you can adjust the method make it so it accepts a delegate or Action or Func.