我有这个程序调用了ask()函数,即使我没有调用它,如我的main函数所示。
static void Main(string[] args)
{
Console.Write("Charlie: " + resp());
Thread.Sleep(2000);
Console.Write(askBack());
Console.ReadKey();
}
public static string ask()
{
string userInput = "";
Console.Write("You: ");
userInput = Console.ReadLine();
return userInput;
}
这是resp():
public static string resp()
{
Connect connect = new Connect();
string throwResponse = "";
if (connect.openConnection() == true)
{
string respond = @"SELECT answer FROM response WHERE question=@_userInput";
MySqlCommand cmd = new MySqlCommand(respond, connect.connection);
cmd.Parameters.AddWithValue("@_userInput", ask());
cmd.ExecuteNonQuery();
throwResponse = Convert.ToString(cmd.ExecuteScalar());
}
return throwResponse;
}
当我打电话给它时,会打印“你:”两次。