特
特尔斐
Unregistered / Unconfirmed
GUEST, unregistred user!
这段代码中用了goto,请问如果不用goto的话该如何写才可完成相同功能?
using System;
class LeapyearTester
{
static int iYear = 1990;
static void Main()
{
Console.WriteLine(" ***************************************************** ");
Console.WriteLine(" * * ");
Console.WriteLine(" * 欢迎使用闰年测试程序 * ");
Console.WriteLine(" * * ");
Console.WriteLine(" * 版本:1.0 * ");
Console.WriteLine(" * 本程序使用C#编写 * ");
Console.WriteLine(" * * ");
Console.WriteLine(" * Wrote by yyh 2003.08.09 * ");
Console.WriteLine(" * * ");
Console.WriteLine(" ***************************************************** ");
Console.WriteLine("");
while (true)
{
Console.Write("请输入要测试的年份:");
ReRead:
String sYear = Console.ReadLine();
try
{
iYear = Convert.ToInt16(sYear, 10);
}
catch
{
Console.Write("");
Console.Write("输入错误,请重新输入:");
goto ReRead;
};
if ((iYear % 400) == 0 || ((iYear % 4) == 0 &&
(iYear % 100) != 0))
{
Console.WriteLine("{0}是闰年", iYear);
}
else
{
Console.WriteLine("{0}不是闰年", iYear);
}
Console.WriteLine("");
Console.WriteLine("退出请按X(x)后回车,继续测试请按回车键。");
char c = (char)Console.Read();
if (c == 'X' || c == 'x')
break;
}
}
}
另外,想请教一个问题,在C#中建立分布式应用是一个怎样的步骤?
using System;
class LeapyearTester
{
static int iYear = 1990;
static void Main()
{
Console.WriteLine(" ***************************************************** ");
Console.WriteLine(" * * ");
Console.WriteLine(" * 欢迎使用闰年测试程序 * ");
Console.WriteLine(" * * ");
Console.WriteLine(" * 版本:1.0 * ");
Console.WriteLine(" * 本程序使用C#编写 * ");
Console.WriteLine(" * * ");
Console.WriteLine(" * Wrote by yyh 2003.08.09 * ");
Console.WriteLine(" * * ");
Console.WriteLine(" ***************************************************** ");
Console.WriteLine("");
while (true)
{
Console.Write("请输入要测试的年份:");
ReRead:
String sYear = Console.ReadLine();
try
{
iYear = Convert.ToInt16(sYear, 10);
}
catch
{
Console.Write("");
Console.Write("输入错误,请重新输入:");
goto ReRead;
};
if ((iYear % 400) == 0 || ((iYear % 4) == 0 &&
(iYear % 100) != 0))
{
Console.WriteLine("{0}是闰年", iYear);
}
else
{
Console.WriteLine("{0}不是闰年", iYear);
}
Console.WriteLine("");
Console.WriteLine("退出请按X(x)后回车,继续测试请按回车键。");
char c = (char)Console.Read();
if (c == 'X' || c == 'x')
break;
}
}
}
另外,想请教一个问题,在C#中建立分布式应用是一个怎样的步骤?