所以我编写了一个简单的代码,将两个不同的数组传递给一个方法,以检查异常。但是有一个问题——当我传递数组时,如果缓存了一个异常,在我的异常“nameof”部分,它并没有说明哪个数组是那个数组,是什么导致了异常。我需要纠正这一点。那么你有什么想法,我怎么能在我的代码中做到这一点?
public class CommonEnd
{
public bool IsCommonEnd(int[] a, int[] b)
{
ValidateArray(a);
ValidateArray(b);
return a.First() == b.First() || a.Last() == b.Last();
}
private void ValidateArray(int[] array)
{
if (array == null)
{
throw new ArgumentNullException(nameof(array), "Array is NULL.");
}
if (array.Length == 0)
{
throw new ArgumentOutOfRangeException(nameof(array), "Array length can't be smaller that 1");
}
}
}