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] }}Below code is use to define how to use this enumerator class UseEnumurator.cs namespace cardenumarator { Public Class StudentDetail { #region[PrivateField] Private string name; Private string age; Private string sex; #endregion[PrivateField] #region[Poperty] /// <summary> /// Gets or sets Name /// </summary> Public string Name { get{return name;} set{name=value;} } /// <summary> /// Gets or sets Age /// </summary> Public string Age { get{return age;} set{age=value;} } /// <summary> /// Gets or sets Sex /// </summary> Public string Sex { get{return sex;} set{sex=value;} } #endregion{Poperty] } Public Class UseEnumurator { /// <summary> /// create the instance of the TransactionRetrieveDAL class from being created. /// </summary> public UseEnumurator() { } public Gettrxcardenumarator<StudentDetail> GetUsersDetail() { StudentDetail student1 = new StudentDetail(); student1.Name="Rahul"; student1.Age="12"; student1. sex="M"; StudentDetail student2 = new StudentDetail(); student2.Name="Rahul"; student2.Age="12"; student2. sex="M"; Gettrxcardenumarator<StudentDetail> StudentDetail = new Gettrxcardenumarator<StudentDetail>(); StudentDetail[0]= student1; StudentDetail[0]= student2; } void Main() { Gettrxcardenumarator<StudentDetail> StudentDetail=GetUsersDetail(); foreach( StudentDetail student in StudentDetail.) { console.writeLine(student.Name); console.writeLine(student.Age); console.writeLine(student.Sex); console.readLine(); } } } }
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] }}
Below code is use to define how to use this enumerator class
UseEnumurator.cs namespace cardenumarator { Public Class StudentDetail { #region[PrivateField] Private string name; Private string age; Private string sex; #endregion[PrivateField] #region[Poperty] /// <summary> /// Gets or sets Name /// </summary> Public string Name { get{return name;} set{name=value;} } /// <summary> /// Gets or sets Age /// </summary> Public string Age { get{return age;} set{age=value;} } /// <summary> /// Gets or sets Sex /// </summary> Public string Sex { get{return sex;} set{sex=value;} } #endregion{Poperty] } Public Class UseEnumurator { /// <summary> /// create the instance of the TransactionRetrieveDAL class from being created. /// </summary> public UseEnumurator() { } public Gettrxcardenumarator<StudentDetail> GetUsersDetail() { StudentDetail student1 = new StudentDetail(); student1.Name="Rahul"; student1.Age="12"; student1. sex="M"; StudentDetail student2 = new StudentDetail(); student2.Name="Rahul"; student2.Age="12"; student2. sex="M"; Gettrxcardenumarator<StudentDetail> StudentDetail = new Gettrxcardenumarator<StudentDetail>(); StudentDetail[0]= student1; StudentDetail[0]= student2; } void Main() { Gettrxcardenumarator<StudentDetail> StudentDetail=GetUsersDetail(); foreach( StudentDetail student in StudentDetail.) { console.writeLine(student.Name); console.writeLine(student.Age); console.writeLine(student.Sex); console.readLine(); } } } }
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: