Gmail 控制台应用程序 C#
Gmail console App C#
我想弄清楚为什么我的菜单方法中出现错误 "Cannot assign to 'loggedIn' because it is a method group"
。任何帮助将不胜感激。代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace GmailClient
{
class Program
{
static string userName="";
static string passWord="";
public static bool loggedIn()
{
if (userName == "")
{
if (passWord == "")
{
return false;
}
else
{
return false;
}
}
else
{
return true;
}
}
static void Main(string[] args)
{
}
public static void menu()
{
Console.WriteLine("Loading menu.");
if ( loggedIn = false)
{
Console.WriteLine("__________Menu__________");
Console.WriteLine("1) Enter your Gmail credentials");
Console.WriteLine("2) Exit the Console");
Console.WriteLine("________________________");
Console.WriteLine("What do you want to do?");
int userchoice = Convert.ToInt32(Console.ReadLine());
if (userchoice == 1)
{
credentials();
}
else if (userchoice == 2)
{
Console.WriteLine("Hope to see you soon!");
Console.ReadKey();
Environment.Exit(0);
}
}
else if (loggedIn = true)
{
Console.WriteLine("__________Menu__________");
Console.WriteLine("1) Enter your Gmail credentials");
Console.WriteLine("2) Check your inbox");
Console.WriteLine("3) Send an e-mail");
Console.WriteLine("4) Exit the Console");
Console.WriteLine("________________________");
Console.WriteLine("What do you want to do?");
int userchoice = Convert.ToInt32(Console.ReadLine());
if (userchoice == 1)
{
credentials();
}
else if (userchoice ==2)
{
getMail();
}
else if (userchoice ==3)
{
sendMail();
}
else if (userchoice ==4)
{
Console.WriteLine("Hope to see you soon!");
Console.ReadKey();
Environment.Exit(0);
}
}
}
public static void credentials()
{
Console.WriteLine("Enter your Gmail address:");
userName = Console.ReadLine();
Console.WriteLine("Enter your Gmail password:");
passWord = Console.ReadLine();
}
public static void getMail()
{
Console.WriteLine("Loading inbox messages");
}
public static void sendMail()
{
Console.WriteLine("Under Construction");
}
}
}
将 if ( loggedIn = false)
更改为 if (!loggedIn())
,将 if (loggedIn = true)
更改为 if (loggedIn())
。
此外,在使用 if
条件检查时,不要使用单个等于 =
。 =
是赋值(例如,您正在为变量 variable = "value"
赋值)。比较时使用双等号 ==
(例如 if (variable == true) ...
)。
对于您的代码,loggedIn
被定义为 method/function。您的代码将其视为 property/variable.
我想弄清楚为什么我的菜单方法中出现错误 "Cannot assign to 'loggedIn' because it is a method group"
。任何帮助将不胜感激。代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace GmailClient
{
class Program
{
static string userName="";
static string passWord="";
public static bool loggedIn()
{
if (userName == "")
{
if (passWord == "")
{
return false;
}
else
{
return false;
}
}
else
{
return true;
}
}
static void Main(string[] args)
{
}
public static void menu()
{
Console.WriteLine("Loading menu.");
if ( loggedIn = false)
{
Console.WriteLine("__________Menu__________");
Console.WriteLine("1) Enter your Gmail credentials");
Console.WriteLine("2) Exit the Console");
Console.WriteLine("________________________");
Console.WriteLine("What do you want to do?");
int userchoice = Convert.ToInt32(Console.ReadLine());
if (userchoice == 1)
{
credentials();
}
else if (userchoice == 2)
{
Console.WriteLine("Hope to see you soon!");
Console.ReadKey();
Environment.Exit(0);
}
}
else if (loggedIn = true)
{
Console.WriteLine("__________Menu__________");
Console.WriteLine("1) Enter your Gmail credentials");
Console.WriteLine("2) Check your inbox");
Console.WriteLine("3) Send an e-mail");
Console.WriteLine("4) Exit the Console");
Console.WriteLine("________________________");
Console.WriteLine("What do you want to do?");
int userchoice = Convert.ToInt32(Console.ReadLine());
if (userchoice == 1)
{
credentials();
}
else if (userchoice ==2)
{
getMail();
}
else if (userchoice ==3)
{
sendMail();
}
else if (userchoice ==4)
{
Console.WriteLine("Hope to see you soon!");
Console.ReadKey();
Environment.Exit(0);
}
}
}
public static void credentials()
{
Console.WriteLine("Enter your Gmail address:");
userName = Console.ReadLine();
Console.WriteLine("Enter your Gmail password:");
passWord = Console.ReadLine();
}
public static void getMail()
{
Console.WriteLine("Loading inbox messages");
}
public static void sendMail()
{
Console.WriteLine("Under Construction");
}
}
}
将 if ( loggedIn = false)
更改为 if (!loggedIn())
,将 if (loggedIn = true)
更改为 if (loggedIn())
。
此外,在使用 if
条件检查时,不要使用单个等于 =
。 =
是赋值(例如,您正在为变量 variable = "value"
赋值)。比较时使用双等号 ==
(例如 if (variable == true) ...
)。
对于您的代码,loggedIn
被定义为 method/function。您的代码将其视为 property/variable.