Why am I ++ "unreachable code"?

EDIT

I leave it here, although it makes me look stupid, because it is a subtle mistake that can bite you if you work late at night and do not pay attention. Kudos to Visual Studio for such an intelligent parser.

I basically skipped that I have nested loops, so the statement is continueuseless here because it continues the loop foreach, not the loop for.

ORIGINAL QUESTION

I run a search in a workbook, looking for a worksheet that matches all string search criteria. In the editor, Visual Studio is i++underlined as "unreachable code."

/// <summary>
/// Finds the first sheet that has cells that match all the criteria.
/// </summary>
/// <param name="wb"></param>
/// <param name="searches"></param>
/// <returns></returns>
public static ISheet FindSheet( this IWorkbook wb, params string[] searches )
{
    if( null == wb || null == searches )
        return null;

    for( int i = 0; i < wb.NumberOfSheets; i++ )
    {
        var sheet = wb.GetSheetAt( i );
        foreach( var search in searches )
        {
            var cell = sheet.FindCell( search );
            if( null == cell )
                continue;
        }

        return sheet;
    }

    return null;
}

, continue : " - null, . , ".

/// <summary>
/// Finds the first sheet that has cells that match all the criteria.
/// </summary>
/// <param name="wb"></param>
/// <param name="searches"></param>
/// <returns></returns>
public static ISheet FindSheet( this IWorkbook wb, params string[] searches )
{
    if( null == wb || null == searches )
        return null;

    for( int i = 0; i < wb.NumberOfSheets; i++ )
    {
        var sheet = wb.GetSheetAt( i );
        if( searches.All( s => null != sheet.FindCell( s ) ) )
            return sheet;
    }

    return null;
}
+4
2

for . , . , foreach continue, foreach. .

- . , , for 0, .

+5

SO > , , , .

, "", - , , , , , :

public static ISheet FindSheet( this IWorkbook wb, params string[] searches )
{
    if( null == wb || null == searches ) { return null; }

    return wb.FirstOrDefault(sh => searches.All(sr => sh.FindCell(sr) != null));
}
+3

Source: https://habr.com/ru/post/1532940/


All Articles