小编MP1*_*MP1的帖子

编写异常辅助方法

我是 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 抛出异常”?任何信息都会有所帮助!谢谢

c# syntax exception throw propagation

1
推荐指数
1
解决办法
940
查看次数

for循环中的箭头符号

有几次我看到在 for 循环中使用类似符号组合的箭头,如下所示:

for(int i = 100; i --> 0;) {
    System.out.println(i);
}
Run Code Online (Sandbox Code Playgroud)

这里发生了什么事?

java

0
推荐指数
1
解决办法
616
查看次数

标签 统计

c# ×1

exception ×1

java ×1

propagation ×1

syntax ×1

throw ×1