我是 C# 新手,正在练习抛出异常。从辅助方法抛出异常以缩短所需的代码量是一种好习惯吗?像这样:
public static void ThrowExcIfNull<T>(T[] array)
{
if (array == null) throw new ArgumentNullException("Array is null");
}
/// <summary>
/// Does Something
/// </summary>
/// <param name="x">The int array to be used</param>
/// <exception cref="ArgumentNullException">Thrown when the string is
/// null</exception> //Is this correct?
/// <returns>Some integer</returns>
public static int SomeMethod(this int[] x)
{
ThrowExcIfNull(x);
//Some code here
}
Run Code Online (Sandbox Code Playgroud)
另外,是否可以编写文档说“从 someMethod 抛出异常”?任何信息都会有所帮助!谢谢
有几次我看到在 for 循环中使用类似符号组合的箭头,如下所示:
for(int i = 100; i --> 0;) {
System.out.println(i);
}
Run Code Online (Sandbox Code Playgroud)
这里发生了什么事?