Friday 3 January 2014

C# Using Enum: GTK style

using System;
using System.Collections;
using Gtk;

namespace EmpIEnum
{
class MainClass
{
public static void Main (string[] args)
{
EmployeeCollection E=new EmployeeCollection();
foreach(Employee e in E)
Console.WriteLine(e.Name+"\t\t"+e.Id+"\t\t"+e.Salary);
Console.WriteLine();
}
}
}



using System;
using System.Collections;

namespace EmpIEnum
{
public class Employee
{
public string name;
public int id;
public long salary;

public Employee (string Name,int Id,long salary)
{
name=Name;
id=Id;
salary=Salary;
}
public string Name{
get {return name;}
set {name=value;}
}

public int Id{
get{return id;}
set {id=value;}
}
public long Salary{
get{return salary;}
set {salary=value;}
}

}

}


using System;
using System.Collections;
namespace EmpIEnum
{
public class EmployeeCollection:IEnumerable,IEnumerator
{
Employee[] empcollection;
int pos=-1;

public EmployeeCollection ()
{
empcollection=new Employee[5]
{
new Employee("Ravi",123,2000),
new Employee("Kiran",234,3000),
new Employee("Ranju",345,4000),
new Employee("Ram",456,5000),
new Employee("Maansi",567,6000),
};
}
public IEnumerator GetEnumerator()
{
return(IEnumerator)this;
}
public bool MoveNext(){
pos++;
return(pos<empcollection.Length);
}
public void Reset(){
pos=0;
}
public object Current{
get{return empcollection[pos];}
}

}
}



No comments:

Post a Comment