c# - IEnumerator implementation problem -


i have code:

public class check21csvrecord {      public string transactiontype;     public string transactioncurrency;     public string reference;     public string paymenttype;      // date of transaction                     public string transactiondate;      public string notes;      // customer data goes here     public string customerfirstname;     public string customerinitial;     public string customerlastname;     public string customerstreetaddress;     public string customercity;     public string customerstate;     public string customerzipcode;      [fieldconverter(converterkind.date, "mm/dd/yy")]      public datetime customerdatebirth;     public string customercountry;     public string customeremail;     public string customerphone;     public string customeripaddress;      // micr line goes here     public string auxiliaryonus;     public string externalprocessingcode;     public string payorbankroutingnumber;     public string payorbankroutingnumbercheckdigit;     public string onus;      // check amount     [fieldconverter(converterkind.double)]     public double amount;      // account credit     public string creditaccountnumber;      public string frontimagepath;     public string backimagepath;      // used define if have image or should build dynamically     public bool isdynamicimage{                 {             return (frontimagepath.length == 0 && backimagepath.length == 0);         }     } }   public class dataprovider <t>:  ienumerator {     private filehelperengine csvreader;      private t currentrecord;     private int currentindex;     private string file;     private t[] collection = new t[5000];      public dataprovider(string csvfile)     {         csvreader = new filehelperengine(typeof(t));         collection = csvreader.readfile(file) t[];          currentrecord = default(t);                     file = csvfile;         reset();     }      public bool movenext()     {         if (++currentindex >= collection.count())         {             return false;         }         else         {                currentrecord = collection[currentindex];         }         return true;      }      public void reset()     {         currentindex = -1;     }      public void dispose()     {      }      public t current     {                 {             return currentrecord;         }     }      object system.collections.ienumerator.current     {         { return currentrecord; }     } } 

when compile - good, when call class:

 var input = new dataprovider<check21csvrecord>("../../../../artifacts/incomingdata/check21/check21.csv");  while (input.movenext())  {        console.writeline(input.current.customerfirstname);  } 

i'm getting following problem: http://screencast.com/t/ndbkntnkmjkt

any ideas how fix?

thanks, dmitry

you should assign file first.

public dataprovider(string csvfile) {                 file = csvfile;     csvreader = new filehelperengine(typeof(t));     collection = csvreader.readfile(file) t[];      currentrecord = default(t);     reset(); } 

Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -