Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Try using a <code>List&lt;&gt;</code>.</p> <pre><code>class Myclass { static List&lt;string&gt; user_Name = new List&lt;string&gt;{ "admin", "user1", "user2" }; static List&lt;string&gt; user_Password = new List&lt;string&gt;{ "admin", "123", "789" }; public static void Check_Method(string u_name, string u_password) { for (int i = 0; i &lt; user_Name.Length; i++) { if (u_name == user_Name[i] &amp;&amp; u_password == user_Password[i]) { MessageBox.Show("login successful"); break; } else { if (i == (user_Name.Length - 1)) MessageBox.Show("Badshow"); } } } public static void add_user(string name, string password) { user_Name.Add(name); user_Password.Add(password); } } </code></pre> <p>Here's a refactored version:</p> <p>Users are contained in a user class.</p> <p>They are <code>IEquatable&lt;&gt;</code> which compares their username/passwords (you might want to consider looking into a <code>Guid</code> to keep them unique).</p> <p>Easily add/remove users.</p> <pre><code>public class User : IEquatable&lt;User&gt; { public User(string name, string password) { Name = name; Password = password; } public string Name { get; set; } public string Password { get; set; } public bool Equals(User other) { if (other == null) return false; return other.Name == Name &amp;&amp; other.Password == Password; } } public class AuthenticationManager { private List&lt;User&gt; LoggedInUsers = new List&lt;User&gt; { new User("Admin", "admin"), new User ("user1", "123"), new User ("user2", "789") }; public bool Authenticate(string userName, string password) { var user = new User(userName, password); //if the user is in the list it will return false otherwise true. return !LoggedInUsers.Any(u =&gt; user.Equals(user)); } public void Login(string name, string password) { LoggedInUsers.Add(new User(name, password)); } public void Logout(string name, string password) { LoggedInUsers.Remove(new User(name, password)); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload