Below class is an example of a custom enumerator class. It is a generic class used to contain details on of the related object. So one can use this class in for each loop and for loop to retrieve data. It can be used in the place of data set .Because in this class you can store objects of a utility class. So each object can contain different value.
Gettrxcardenumarator.cs
namespace cardenumarator
{
#region[Directive]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
#endregion[Directive]
/// <summary>
/// This class used get
enumerated data for gettrxcard
/// </summary>
/// <typeparam name="T">Generic type</typeparam>
public class Gettrxcardenumarator<T> : IEnumerable, IEnumerator
{
#region[privateData]
private List<T>
gettrxcard = new List<T>();
private int inex =
-1;
#endregion[privateData]
#region[Property]
/// <summary>
/// Gets Length
/// </summary>
public int Length
{
get { return
gettrxcard.Count; }
}
/// <summary>
/// Gets gettrxcard
/// </summary>
object IEnumerator.Current
{
get
{
if (inex != -1)
{
return gettrxcard[inex];
}
else
{
return null;
}
}
}
/// <summary>
/// This is the class
indexing concept
/// </summary>
/// <param name="index">Int data type</param>
/// <returns>Generic type</returns>
public T this[int index]
{
set
{
gettrxcard.Add(value);
}
get
{
return gettrxcard[index];
}
}
#endregion[Property]
#region[PublicMethod]
/// <summary>
/// GetEnumerator function
is used to iterate in foreach loop
/// </summary>
/// <returns>IEnumerator
data type</returns>
public IEnumerator
GetEnumerator()
{
return this;
}
/// <summary>
/// It i used to get the
next record
/// </summary>
/// <returns>A<see cref="System.Boolean"/> value returing true or false </returns>
public bool
MoveNext()
{
if (inex == gettrxcard.Count - 1)
{
Reset();
return false;
}
inex++;
return true;
}
/// <summary>
/// Used to reset the value
/// </summary>
public void Reset()
{
this.inex = -1;
}
#endregion[PublicMethod]
}
}
Join the conversation! Your thoughts help the community grow.