小编Mos*_*sep的帖子

c#并非所有代码路径都以简单方法返回值错误

类的简单程序可以计算单词并获得上面的错误,这让我很生气.

int words; //variable to hold word count.

//WordCount methos will count the spaces and punciation.
private int WordCount(string str)
{
    int words = 0; //the number of words counted

    //count the white spaces and punctuation.
    foreach (char ch in str)
    {
        if (char.IsWhiteSpace(ch))
        {
            words++;
        }
        if (char.IsPunctuation(ch))
        {
            words++;
        }

        //return number of words
        return words;
    }
}
Run Code Online (Sandbox Code Playgroud)

c#

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

标签 统计

c# ×1