c# - does not contain a static main method for suitable entry point -


keep getting error message not contain static main method suitable entry point. able explain error me , possibly me fix it? thanks. new c#

 {     class authenticator     {          private dictionary<string, string> dictionary = new dictionary<string, string>();          public void intialvalues()         {             dictionary.add("username1", "password1");             dictionary.add("username2", "password2");             dictionary.add("username3", "password3");             dictionary.add("username4", "password4");             dictionary.add("username5", "password5");         }          public bool authenticate(boolean authenticated)         {             console.writeline("please enter username");             string inputusername = console.readline();              console.writeline("please enter password");             string inputpassword = console.readline();              if (dictionary.containskey(inputusername) && dictionary[inputusername] == inputpassword)             {                 authenticated = true;             }             else             {                 authenticated = false;             }              return authenticated;         }     } } 

if of code consists of block shown above error more clear. main method required in program.

the main method is, convention, default point code starts executing. can here more in depth explanation

so, example, need add following code

class authenticator {     static void main(string[] args)     {          authenticator au = new authenticator();          au.initialvalues();          if(au.authenticate())             console.writeline("authenticated");          else             console.writeline("not authenticated");          console.writeline("press enter end");          console.readline();      }      // move boolen variable inside method     public bool authenticate()     {         bool authenticated = false;         console.writeline("please enter username");         string inputusername = console.readline();          console.writeline("please enter password");         string inputpassword = console.readline();          if (dictionary.containskey(inputusername) && dictionary[inputusername] == inputpassword)         {             authenticated = true;         }         else         {             authenticated = false;         }          return authenticated;     } } 

by way, should remove parameter passed in input authenticate method. should declare internal variable, set depending on outcome of check , return it.

however, remove variable altogether writing

    ....     return (dictionary.containskey(inputusername)) &&             (dictionary[inputusername] == inputpassword) } 

Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -