class Program
{
static void Main(string[] args)
{
int result;
Console.WriteLine("请输入一个字符串,查看是否能转化成整数类型");
if (myTryParse(Console.ReadLine(), out result))
{
Console.WriteLine("转化成功,结果是{0}", result);
}
else
{
Console.WriteLine("转化失败,您的输入不能转化成整数类型");
}
Console.ReadKey();
}
/// <summary>
/// 试着转化字符串为int类型,如果转化成功返回true,
/// </summary>
/// <param name="str">要转化的字符串</param>
/// <param name="result">参数返回转换后的int</param>
/// <returns>是否转化成功,成功:true 失败:false</returns>
public static bool myTryParse(string str, out int result)
{
result = 0;
try
{
result = Convert.ToInt32(str);
return true;
}
catch (Exception ex)
{
return false;
}
}
public static int totol(int[] shu, out int maxNum, out int minNum)
{
int totol = 0;
maxNum =shu[0];
minNum =shu[0];
for (int i = 0; i < shu.Length; i++)
{
totol += shu[i];