Java 将布尔类添加到类数组中
我有一些用Java编写的代码,我想将其转换为Xamarin(C#)。我怎么能用C写这个 然后给每一个类似的包装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
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;
}