【发布时间】:2015-07-06 13:56:35
【问题描述】:
我有一个项目使用按钮访问通用集合中的下一个或上一个元素 学生类有 3 个属性:字符串 lastname、firstname 和 city。 谁能帮我启用它? 我认为它可能与 IEnumerator() 有关,但我卡住了
public partial class MainWindow : Window
{
List<Student> Students = new List<Student>();
public MainWindow()
{
InitializeComponent();
txtFirstName.Clear();
txtLastName.Clear();
txtCity.Clear();
}
private void btnCreateStudent_Click(object sender, RoutedEventArgs e)
{
Student stu = new Student();
stu.Firstname = txtFirstName.Text;
stu.Lastname = txtLastName.Text;
stu.City = txtCity.Text;
//List<Student> Students = new List<Student>();
Students.Add(stu);
//string s = Convert.ToString(Students.Count);
MessageBox.Show("Updated");
txtFirstName.Clear();
txtLastName.Clear();
txtCity.Clear();
}
private void btnNext_Click(object sender, RoutedEventArgs e)
{
// I need to access to the next element by press this button, the current is the member that i has just created
}
}
【问题讨论】:
-
你是否被 3 个属性卡住了?
-
不,我认为3个属性都可以,只是想知道如何访问列表中的元素?