小编Ale*_*key的帖子

并非所有代码路径都返回一个值for循环

此代码将比较存储在文本文件中的用户名密码.我认为这是因为for循环,它可能很简单但我无法看到它.

public int loginCheck()
{ 
    //-----------------------------------------------------------------
    string[] users = File.ReadLines("Username_Passwords").ToArray();
    //line of text file added to array 
    //-----------------------------------------------------------------

    for (int i = 0; i < users.Length; i++)
    {
        string[] usernameAndPassword = users[i].Split('_');
        //usernames and passwords separated by '_' in file, split into two strings

        if (_username == usernameAndPassword[0] && _password == usernameAndPassword[1])
        {
            return 1;
            //return 1, could have used bool
        }
        else
        {
            return 0;
        }
    }
Run Code Online (Sandbox Code Playgroud)

c# methods for-loop return

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

标签 统计

c# ×1

for-loop ×1

methods ×1

return ×1