我在c#中有一个方法,它将Color作为参数。当试图从java调用该方法时,方法要求传递ValueType类型的参数。 ValueType在这里意味着什么。我应该做任何演员。
以下是C#代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
namespace Algebra
{
public class Calculation
{
public int x { get; set; }
public int y { get; set; }
private Color clr;
public Color Clr
{
get { return clr; }
set { clr = value; }
}
public sampleclass sam { get; set; }
public int add(int num1, int num2)
{
// Console.WriteLine(num1 + num2);
return num1 + num2;
}
public int sub(int num1, int num2)
{
return num1 - num2;
}
public int mul()
{
return (x * y);
}
public Calculation()
{
x = 20;
y = 10;
Console.WriteLine("in cons ");
}
public void print(String st,Color c)
{
sam.str = st;
Console.WriteLine(sam.str);
Console.WriteLine(c.ToString());
}
}
public class sam
{
Calculation cal = new Calculation();
public void show()
{
//cal.sa
}
}
public class sampleclass
{
public String str { get; set; }
public sampleclass()
{
str = "sample class";
}
}
}
以下是java代码:
Calculation c = new Calculation();
sampleclass s = new sampleclass();
c.setx(100);
c.sety(33);
String s1 = new String("hello");
c.print(s1,/*Here it is asking for ValueType*/); // original is Color Type in C# application.
谢谢, 帕