怎么把这段javascript函数转换成C#...

gmkiy121 2009-07-15 11:30:48
function GetNum( Num_A, Num_B){
var out_Num=new Array();
var line,aRatio,nowRatio,bRatio;
var nowType="";
if (Num_A <= 1000 && Num_B <= 1000){
out_Num[0]=Num_A;
out_Num[1]=Num_B;
return out_Num;
}
line=2000 - ( Num_A + Num_B );
if (Num_A > Num_B){
aRatio=Num_B;
nowType="a"
}else{
aRatio = Num_A;
nowType="b"
}
if (((2000 - line) - aRatio) > 1000){

nowRatio = (aRatio + line) * (-1);
}else{

nowRatio=(2000 - line) - aRatio;
}
if (nowRatio < 0){
bRatio = Math.floor(Math.abs(1000 / nowRatio) * 1000) ;
}else{
bRatio = (2000 - line - nowRatio) ;
}
if (nowType == "a"){
out_Num[0]=aRatio;
out_Num[1]=bRatio;
}else{
out_Num[0]=bRatio;
out_Num[1]=aRatio;
}
return out_Num;
}
请教下.怎么把这段javascript函数转换成C#...
...全文
32 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
我姓区不姓区 2009-07-15
  • 打赏
  • 举报
回复
逻辑及语法都很简单易懂啊,为什么不自己尝试一下呢

public int[] GetNum(int Num_A, int Num_B)
{
int[] out_Num = new int[2];
int line,aRatio,nowRatio,bRatio;
string nowType="";
if (Num_A <= 1000 && Num_B <= 1000)
{
out_Num[0] = Num_A;
out_Num[1] = Num_B;
return out_Num;
}
line=2000 - ( Num_A + Num_B );
aRatio = Math.Min(Num_A, Num_B);
nowType = Num_A > Num_B ? "a" : "b";
if (((2000 - line) - aRatio) > 1000)
nowRatio = (aRatio + line) * (-1);
else
nowRatio=(2000 - line) - aRatio;
if (nowRatio < 0)
bRatio = (int)Math.Floor(Math.Abs(1000 / nowRatio) * 1000) ;
else
bRatio = (2000 - line - nowRatio) ;
if (nowType == "a")
{
out_Num[0]=aRatio;
out_Num[1]=bRatio;
}
else
{
out_Num[0]=bRatio;
out_Num[1]=aRatio;
}
return out_Num;
}

110,566

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧