Cav*_*rob 3 return function return-value
我有一个名为FindSpecificRowValue的函数,它接受一个数据表并返回包含特定值的行号.如果找不到该值,我想向调用函数指示.
是最好的方法:
ang*_*son 13
就个人而言,我不会使用该方法名称.
我会改为两种方法:
TryFindSpecificRow
FindSpecificRow
Run Code Online (Sandbox Code Playgroud)
这将遵循Int32.Parse/TryParse的模式,在C#中它们可能如下所示:
public static Boolean TryFindSpecificRow(DataTable table, out Int32 rowNumber)
{
if (row-can-be-found)
{
rowNumber = index-of-row-that-was-found;
return true;
}
else
{
rowNumber = 0; // this value will not be used anyway
return false;
}
}
public static Int32 FindSpecificRow(DataTable table)
{
Int32 rowNumber;
if (TryFindSpecificRow(table, out rowNumber))
return rowNumber;
else
throw new RowNotFoundException(String.Format("Row {0} was not found", rowNumber));
}
Run Code Online (Sandbox Code Playgroud)
编辑:更改为更适合问题.