Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 将布尔类添加到类数组中_Java_C#_Class_Xamarin - Fatal编程技术网

Java 将布尔类添加到类数组中

Java 将布尔类添加到类数组中,java,c#,class,xamarin,Java,C#,Class,Xamarin,我有一些用Java编写的代码,我想将其转换为Xamarin(C#)。我怎么能用C写这个 然后给每一个类似的包装 if (mStartForeground != null) { mStartForegroundArgs[0] = Integer.valueOf(id); mStartForegroundArgs[1] = notification; invokeMethod(mStartForeground, mStartForegroundArgs

我有一些用Java编写的代码,我想将其转换为Xamarin(C#)。我怎么能用C写这个

然后给每一个类似的包装

if (mStartForeground != null) {
        mStartForegroundArgs[0] = Integer.valueOf(id);
        mStartForegroundArgs[1] = notification;
        invokeMethod(mStartForeground, mStartForegroundArgs);
        return;
    }
在C#中,它被称为类型而不是类。事物的名称有点不同:

private static readonly Type[] mSetForegroundSignature = new Type[] { typeof(bool) }; 
c#等价于
类型
,而对于
布尔类
则是
typeof(bool)
——如果您想了解更多有关c#反射的信息,请查看。以下是翻译后的代码:

  • 签名:

    private static readonly Type[] mSetForegroundSignature = new Type[] { typeof(bool) };
    private static readonly Type[] mStartForegroundSignature = new Type[] { typeof(int), typeof(Notification) };
    private static readonly Type[] mStopForegroundSignature = new Type[] { typeof(bool) };
    
  • 获取方法对象:

    System.Reflection.MethodInfo mStartForeground = new this.GetType().GetMethod("startForeground", mStartForegroundSignature);
    
  • 调用方法:

    if(mStartForeground != null) {
        mStartForegroundArgs[0] = Convert.ToInt32(id);
        mStartForegroundArgs[1] = notification;
        //invoke via reflection (it may be different to invokeMethod?)
        mStartForeground.Invoke(instance, mStartForegroundArgs);
        return;
    }
    

    感谢您的评论,但在本例中,它给出了关于的信息。调用此错误“Object type Java.Lang.Integer无法转换为target type:System.Int32”private Java.Lang.Object[]mStartForegroundArgs=new Java.Lang.Object[2];是mstartforegroundarg的类型我不知道.NET中应该引用什么
    Java.Lang.Object
    Java.Lang.Integer
    ,但是
    Convert.ToInt32
    那么将
    id
    转换为整数不是正确的方法。。。
    System.Reflection.MethodInfo mStartForeground = new this.GetType().GetMethod("startForeground", mStartForegroundSignature);
    
    if(mStartForeground != null) {
        mStartForegroundArgs[0] = Convert.ToInt32(id);
        mStartForegroundArgs[1] = notification;
        //invoke via reflection (it may be different to invokeMethod?)
        mStartForeground.Invoke(instance, mStartForegroundArgs);
        return;
    }