-1

I can't understand why this error occurs:

public string GetStatusText(string abc) {
   string status = "";

   STATUSDTO StatusList = new STATUSDTO();
   StatusList.LoadByMasterWayBill(abc);

   // this method return List<STATUSDTO>    

   bool has190s = false;
   bool hasother = false;

   foreach(V_TMSDetail_STATUSDTO v in StatusList) {
       if (v.Status == "190" || v.Status == "191") has190s = true;
       else hasother = true;
   }

   if (has190s && hasother) status = "Partially Submitted";
   else if (has190s && !hasother) status = "Submitted";
   else if (!has190s && hasother) status = "Not Submitted";

   return status;
}

When I compile this program, it gives me this error:

foreach statement cannot operate on variables of type because does not contain a public definition for 'GetEnumerator'

Please help me to fix it.

Damien
  • 1,161
  • 2
  • 19
  • 31

2 Answers2

1

The foreach statement in C# does only work on collections that implement the System.Collections.IEnumerable or the System.Collections.Generic.IEnumerable<T>. The error that you get tells you that the collection you have does not contain a definition for the public GetEnumerator method, which is provided by these interfaces.

See https://msdn.microsoft.com/nl-nl/library/ttw7t8t6.aspx for more information.

RFerwerda
  • 1,267
  • 2
  • 10
  • 24
0

Its a guess based on the hanging comment... StatusList does not implement an enumerator. I'm guessing you are trying to loop over the list that is returned by LoadByMasterWayBill

var myList = StatusList.LoadByMasterWayBill(abc);

foreach(V_TMSDetail_STATUSDTO v in myList) {
   //code above
}
Nix
  • 57,072
  • 29
  • 149
  • 198