Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- /**
- @Author: Sajmon
- */
- namespace Practise2
- {
- public class Student
- {
- private String name;
- private int age;
- public Student(String name, int age) {
- this.name = name;
- this.age = age;
- }
- public String GetName()
- {
- return this.name;
- }
- public int GetAge()
- {
- return this.age;
- }
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Collections;
- /**
- @Author: Sajmon
- */
- namespace Practise2
- {
- public class StudentList : IEnumerable {
- private List<Student> students;
- private int index;
- public StudentList()
- {
- this.students = new List<Student>();
- this.index = -1;
- }
- public IEnumerator GetEnumerator() {
- return (students as IEnumerable).GetEnumerator();
- }
- public void Add(Student item)
- {
- this.students.Add(item);
- }
- public Student Current {
- get
- {
- return this.students[index];
- }
- }
- public void Reset()
- {
- this.index = -1;
- }
- public Boolean HasNext() {
- index++;
- if (index < students.Count)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Practise2;
- /**
- @Author: Sajmon
- */
- namespace Program
- {
- class Program
- {
- static void Main(string[] args)
- {
- StudentList students = new StudentList();
- Student student = new Student("Peter Bednar", 28);
- Student student2 = new Student("Jiri Walder", 34);
- Student student3 = new Student("Lumir Navrat", 30);
- Student student4 = new Student("Michal Kratky", 42);
- Student student5 = new Student("Radoslav Fasuga", 35);
- students.Add(student);
- students.Add(student2);
- students.Add(student4);
- students.Add(student5);
- students.Add(student3);
- while (students.HasNext()) {
- Console.WriteLine(students.Current.GetName() + " " + students.Current.GetAge());
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment