2017-03-09 5 views
-2

gmailPasswordgmailAddressのクラスレベルの変数を作成し、メッセージを確認したりメールを送信する前にログインしているかどうかを確認する必要があります。私はそれを解決しようとしましたが、それを理解できないようです。C#ユーザーのGmailアカウントと対話するGmailアプリケーションを作成する。 gmailPasswordとgmailAddressのクラスレベルの変数を作成する必要があります

static void Main(string[] args) 
{ 

    int userSelection; 
    do 
    { 
     userSelection = Menu(); 

     if (userSelection == 2) 
     { 
      loggingOn(); 
     } 

     else if (userSelection == 2) 
     { 
      getMail(); 
     } 

     else if (userSelection == 4) 
     { 
      sendMail(); 
     } 

    } 
    while (userSelection != 4); 
} 


public static int Menu() 
{ 
    if (loggedIn()) 
    { 
     Console.WriteLine("__________Menu__________"); 
     Console.WriteLine("1) Close the application"); 
     Console.WriteLine("2) Enter your credentials"); 
     Console.WriteLine("3) Check for messages "); 
     Console.WriteLine("4) Send a message"); 
     Console.WriteLine("________________________"); 
    } 
    else 
    { 
     Console.WriteLine("____________Menu____________"); 
     Console.WriteLine("1) Close the application"); 
     Console.WriteLine("2) Enter your Credentials"); 
     Console.WriteLine("____________________________"); 
     Console.WriteLine("what would like to do?"); 
    } 
    return Convert.ToInt32(Console.ReadLine()); 

} 

public static bool loggedIn() 
{ 

    if (gmailAddress == "" || gmailPassword == "") 
    { 
     return false; 
    } 
    else 
    { 
     return true; 
    } 
} 

public static void loggingOn() 
{ 
    Console.WriteLine("Enter your gmail address: "); 
    gmailAddress = Console.ReadLine(); 

    Console.WriteLine("Enter your gmail password"); 
    gmailPassword = Console.ReadLine(); 
} 

public static void getMail() 
{ 
    string[] messages = Gmail.getMail(gmailAddress, gmailPassword); 
    Console.WriteLine(); 
    Console.WriteLine("_____Messages_____"); 
    for (int i = 0; i < messages.Length; i++) 
    { 
     Console.WriteLine(messages[i]); 
     Console.WriteLine(); 
    } 
    Console.WriteLine("_____________"); 
} 

static void sendMail() 
{ 
    Console.WriteLine("To address :"); 
    string toAddress = Console.ReadLine(); 
    Console.WriteLine("Subject :"); 
    string subject = Console.ReadLine(); 
    Console.WriteLine("Message :"); 
    string messageBody = Console.ReadLine(); 
    Gmail.sendMail(gmailAddress, gmailPassword, toAddress, subject, messageBody); 
    Console.WriteLine("message sent"); 
} 
+0

どのようなエラーが表示されますか? – Scovetta

+0

cs0103現在のコンテキストにdoesnotが存在しません –

+0

あなたは、クラスやフィールドの表示を怠ったプログラムのクラスレベルの変数について質問しています。 "私はそれを理解することはできません"という質問ではありません。あなたの実際の仕事を示し、*質問*をしてください。あなたの質問は「フィールドとは何か」ですか? –

答えて

0

あなたは型の変数IsAuthorizedを宣言することができますbool

public static bool IsAuthorized {get;set;} 

これは、ユーザーが正常に

public static bool loggedIn() 
{ 

    if (gmailAddress == "" || gmailPassword == "") 
    { 
     return false; 
    } 
    else 
    { 
     IsAuthorized = true; 
     return true; 
    } 
} 

にログインしているときtrueにその値を設定して行います、あなたは何をしますか小切手のようなSendMailのような

static void sendMail() 
{ 
    if(IsAuthorized) 
    { 
    Console.WriteLine("To address :"); 
    string toAddress = Console.ReadLine(); 
    Console.WriteLine("Subject :"); 
    string subject = Console.ReadLine(); 
    Console.WriteLine("Message :"); 
    string messageBody = Console.ReadLine(); 
    Gmail.sendMail(gmailAddress, gmailPassword, toAddress, subject, messageBody); 
    Console.WriteLine("message sent"); 

    } 
     else 
    { 
       loggingOn(); 

    } 
} 

loggedinが使用されていないかどうかを確認してからloggingOn()に移動します。それ以外の場合はメールを送信します。他の方法でもこれを行うことができます。

関連する問題