简体   繁体   中英

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

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM