0

Getting Error as "foreach statement cannot operate on variables of type object" in journey.Classlist which is in foreach.

var ClassesToGetFares = LobjSupplierResponse.trainBtwnStnsList.Select(x => new { trainno = x.trainNumber,departure = x.departureTime,fromstation = x.fromStnCode,tostation = x.toStnCode,Classlist = x.avlClasses}).ToList();
        
foreach (var journey in ClassesToGetFares)
{
   
    foreach (var journeyClass in journey.Classlist)
    {
        LstrUrl = "avlFareenquiry/" + journey.trainno + "/" + journey.departure + "/" + journey.fromstation + "/" + journey.tostation + "/" + journeyClass + "/GN/N";
        Lobjrestclient = new RESTClient(httpVerb.POST, LstrUrl);

        ClsSupplierFareEnquiry LobjFareEnquiry = new ClsSupplierFareEnquiry()
        {
            enquiryType = "3",
            masterId = "WALHIND00000",
            moreThanOneDay = "false",
            reservationChoice = "99"
        };

        string LstrJsonData = JsonConvert.SerializeObject(LobjFareEnquiry);
        LstrApiData = Lobjrestclient.makeRequest_POST("IRCTC", "");
    }
}

image

urmat abdykerimov
  • 427
  • 1
  • 7
  • 17
  • Please share a [mcve]. Particularly how `avlClasses` is declared. – mjwills Jul 18 '21 at 11:07
  • @mjwills public object avlClasses { get; set; } – VIGNESH WARAN Jul 18 '21 at 12:12
  • 1
    avlClasses is of type `object` which does not implement `IEnumerable` or `IEnumerable`. I'm guessing it was supposed to have an iterable type and this is already cleared up, otherwise read up https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/statements/iteration-statements#the-foreach-statement – mfroeh Jul 18 '21 at 19:00
  • Looks like a duplicate of [Foreach statement cannot operate on variables of type 'object' because 'object' does not contain a public definition for 'GetEnumerator'](https://stackoverflow.com/q/48071088) or [foreach statement cannot operate on variables of type 'object'](https://stackoverflow.com/q/27427692) or [ForEach over Object error](https://stackoverflow.com/q/8806114), agree? – dbc Jul 18 '21 at 22:22

0 Answers0