gpt4 book ai didi

c# - MathUtilities C# 异常处理

转载 作者:行者123 更新时间:2023-11-28 20:55:50 24 4
gpt4 key购买 nike

我需要编写一个程序来测试所有的双关语是否正确。
到目前为止我没有遇到任何问题,但我不知道如何处理异常。
如果 n 超过 9,则需要抛出异常。在 visual 2012 上运行此类是否有技巧?在大学里,它在 visual 2010 上运行良好,但在家里,2012 年它无法运行。

调用测试

 [TestMethod]
public void Test_Factorial10()
{
int result = this.Factorial(-3);
Assert.AreEqual(false, result);
}

函数:

public int Factorial(int n)
{
if (n > 9)
{
throw new ArgumentException("max value is 9", "n");
}

else if (n == 1 || n == 0) //
return 1;

else
return n * Factorial(n - 1);
}

最佳答案

如果你在代码中写了 rezultatom 这个词它不起作用,把它改成//rezultatom

[TestMethod]
public void Test_Factorial10()
{
int result = this.Factorial(-3);
Assert.AreEqual(false, result);//rezultatom
}

关于c# - MathUtilities C# 异常处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21042655/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com