我是使用C#编程的初学者,我的讲师给了我们一个棘手的项目。 我已经设法完成除了......数组之外的所有数据!C#数组帮助需要请
长话短说,我有5个文本框,所有这些文本框都从用户那里接受输入。这个信息是在丰富的文本框中显示被存储到一个数组,然后按顺序列出(出生顺序的日期),我列出我已经成功下方做代码:
private void button2_Click(object sender, EventArgs e)
{
{
bc[0] = new Student();
bc[1] = new Student(Convert.ToInt32(textBox1.Text), "Mary", "Ford");
bc[2] = new Student(1254, "Andrew", "White");
bc[3] = new Student(1256, "Liam", "Sharp", " ");
bc[4] = new Student(1266, "Michael", "Brown", " ");
for (int i = 0; i < 5; i++)
{
string bcString = bc[i].studentToString() + "\r\n";
richTextBox1.AppendText(bcString);
}
}
}
CLASS "Student":
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Assignment_2
{
class Student
{
private int accountNum;
private string firstName;
private string lastName;
private string balance;
// first constructor
public Student()
{
accountNum = 0;
firstName = "";
lastName = "";
balance = "";
}
// second constructor
public Student(int accValue, string firstNameVal, string lastNameVal)
{
accountNum = accValue;
firstName = firstNameVal;
lastName = lastNameVal;
balance = "";
}
// third constructor
public Student(int accValue, string firstNameVal,
string lastNameVal, string balanceValue)
{
accountNum = accValue;
firstName = firstNameVal;
lastName = lastNameVal;
balance = balanceValue;
}
public int AccountNum
{
get
{
return accountNum;
}
set
{
accountNum = value;
}
}
public string FirstName
{
get
{
return firstName;
}
set
{
firstName = value;
}
}
public string studentToString()
{
return (Convert.ToString(accountNum) + " " + firstName +
" " + lastName + " " + balance);
}
}
}
你上哪儿去定义'bc'? – 2013-03-20 19:38:52
你的实际问题是什么?请发布任何编译器错误或异常消息。 – 2013-03-20 19:39:29
你的问题有哪些症状?错误讯息?意外的行为?请帮助我们帮助你! – Sebivor 2013-03-20 19:40:17