我对 .NET 框架中的 C# 编码比较陌生。我正在使用 Visual Studios 10。我觉得这是一个简单的问题,但是无论我尝试使用可见性,它都行不通。这是错误最少的“尝试”。我想将这些类与 Windows 应用程序表单代码分开。也许这就是为什么它不能正常工作的原因,因为当我第一次运行一个(凌乱的)Windows 应用程序表单代码时,它工作了。现在把它分成一个更整洁的包,它不会。请看一下代码并告诉我我忽略了什么。我已经搜索了当然以及谷歌搜索的问题,但问题是这个错误主要与数组有关。对我来说不是。
这是错误:
“adm_LogOn”是一个“变量”,但用作“方法”DemoTestEditor\DemoTestEditor\Form1.cs
private void buttonAdmLogOn_Click(object sender, EventArgs e)
{
// The console commands (above and below Writes to the Output.
// Messagebox also works but I think it's too "in your face"
Console.WriteLine("Admin Log On Button pressed.");
AdminClasses adm_LogOn = new AdminClasses(); // Creates a new object instance myALogOn
this.admTicket = adm_LogOn(userName.Text, passWord.Text);
if (this.admTicket != null)
{
Console.WriteLine("Got Ticket: " + this.admTicket);
this.buttonAdmLogOn.Enabled = true;
this.buttonAdmLogOff.Enabled = false;
}
}
这是它在单独的 Admin.classes.cs 代码中调用的类。
public string adm_LogOn(string username, string password)
{
// Initialize a (new object) adm service to work with.
SmartConnectionAdmin.SmartConnectionAdminService adm = new SmartConnectionAdmin.SmartConnectionAdminService();
// Setting up the arguments for the webservice (LogOnRequest) parameters
string ticket = null;
string server = null;
string clientName = "C# Client Suus";
string domain = null;
string clientAppName = "C# Tester Suus";
string clientAppVersion = null;
string clientAppSerial = null;
string clientAppCode = null;
try
{
// Place call with the above arguments
adm.LogOn(username, password, ref ticket, server, clientName, domain, clientAppName, clientAppVersion, clientAppSerial, clientAppCode);
// Displays the retrieved ticket
Console.WriteLine("The following ticket has been received: {0}", ticket);
}
catch (Exception e)
{
MessageBox.Show("Error: " + e.Message, "Oops!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
Console.WriteLine("UserName checked.");
return ticket;
}
}