简体   繁体   English

如何将接口作为参数传递给方法 C#

[英]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:我正在 Xamarin.android 做一个项目,我正在按照 java 示例代码通过蓝牙将智能卡读卡器 (Acr1255u-j1) 连接到 android,我得到了一个方法:

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 startscan 方法的第二个参数是接口“BluetoothTerminalManager.TerminalScanCallback()”,但是当我尝试将其转换为 c# 时,它显示此错误: 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 .您不能在 C# 中执行内联接口实现,您需要为该接口提供 class 实现,或者如果您可以调整方法使其接受委托ActionFunc

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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