c#数组中的错误-"不包含"定义.代码包括在内
本文关键字:quot 代码 定义 包括 包含 错误 数组 | 更新日期: 2023-09-27 18:06:47
我正在尝试为大学创建一个简单的ATM程序。我们什么也没学到,我只是试着把我的程序和"老师"的代码进行比较。到目前为止,我做得很好,但得到这个错误:'atmproject。"Custlogin"不包含数字的定义。我用粗体和斜体突出显示了错误代码。
下面是我的代码:using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace atmproject
{
public partial class custlogin : Form
{
public custlogin()
{
InitializeComponent();
}
//VARIABLES
int i = 0;
public static int found = -1;
private void loginexitbtn_Click(object sender, EventArgs e)
{
this.Close();
form1welc.ActiveForm.Show();
}
// VALIDATE THE ACCOUNT EXISTS IN THE DATA ARRAY
private void loginwithdbtn_Click(object sender, EventArgs e)
{
for (i = 0; i < createcust.number; i++)
{
if (loginaccbox.Text == createcust.accountArray[i])
{
found = i; //found it
i = custlogin.***number***; // stop looping
}
}
if (found == -1)
{
MessageBox.Show("Account does not exist");
}
else
{
// VALIDATE THE PIN IS CORRECT
if (loginpinbox.Text != createcust.pinArray[found])
{
MessageBox.Show("Not a valid PIN");
}
else
{
//LOAD THE CASH FORM
withdrawselect cash = new withdrawselect();
this.Close();
cash.Show();
}
}
}
}
}
这是我老师的代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace LittleBank
{
public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();
}
// VARIABLES
int i = 0;
public static int found = -1;
private void btnContinue_Click(object sender, EventArgs e)
{
// VALIDATE THE ACCOUNT EXISTS IN THE DATA ARRAY
for (i = 0; i < Form2.number; i++)
{
if (txtAccount.Text == Form2.accountArray[i])
{
found = i; // found it
i = Form2.number; // stop looping
}
}
if (found == -1)
{
MessageBox.Show("Account doest not exist ");
}
else
{
// VALIDATE THE PIN IS CORRECT
if (txtPin.Text != Form2.pinArray[found])
{
MessageBox.Show("Not a Valid Pin");
}
else
{
//LOAD THE CASH FORM
Form4 Cash = new Form4();
this.Close();
Cash.Show();
}
}
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
Form1.Welcome.Show();
}
private void Form3_Load(object sender, EventArgs e)
{
}
private void txtAccount_TextChanged(object sender, EventArgs e)
{
}
}
}
我已经改变了她的名字的形式;她的表格2是我最喜欢的。我将txtAccount更改为loginaccbox的原因是因为在她的代码中,所有文本框在表单中都被命名为相同的,所以我将每个文本框命名为与它的表单相关,以便在调用时区分(当我说调用时我是否有意义?)
另一件事我不明白的是为什么我得到一个错误的那行,但几行,createcust。数字没有错误?这可能是因为createcust确实有一个数字的定义,所以我查看了这种形式的变量,发现有"静态公共字符串int number = 0;"。我将其复制到customlogin,但错误仍然存在。我把它改成了公共静态,还在。帮助吗?
您的custlogin
类没有名为number
的成员。注意,在教师的代码中,所讨论的类被称为Form3
,但number
是在一个名为Form2
的类上定义的。据推测,在您所展示的代码之外,有一个名为Form2
的类,类有一个名为number
的成员。具体来说是static
成员number
。你的代码没有引用另一个类,它引用的是它自己的类,这个类没有这个成员。
您还需要定义教师示例中的其他类(未在您发布的代码中显示)。