为gmailpassword和gmailaddress编写一个方法 [英] Write a method for gmailpassword and gmailaddress

查看:94
本文介绍了为gmailpassword和gmailaddress编写一个方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在获取名称'gmailPassword'和'gmaillAddress'在当前上下文中不存在。我知道我必须为它写一个方法,但不知道如何



I keep getting The name 'gmailPassword' and 'gmaillAddress' does not exist in the current context. I know i have to write a method for it but have no idea how to

class Program
    {
        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");
        }
    }
    }
}





我尝试了什么:



还没有。我试着写我认为会起作用但它没有



What I have tried:

Nothing yet. i tried writing what i thought would work but it hasnt

推荐答案

声明这些变量



declare these variables

class Program
    { 
static string gmailAddress = "";
static string gmailPassword =""; 
        static void Main(string[] args)
        {


这篇关于为gmailpassword和gmailaddress编写一个方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆