locked
Cannot use more than one type in a for, using, fixed, or declaration statement RRS feed

  • Question

  • User265788195 posted
    private IEnumerable<StationEvent> GetStationEvents()
    {
    
        string StationDate = ReportCalculationService.GetStationDate(stationTableName);           
        var SEDateTime = Convert.ToDateTime(StationDate);  
    
        foreach (var record in data.OrderBy(x => x.DateTimeNum))
        {
    	    if (record.ST >= 3 && lastRecord.ST < 3)                            
               startDateNum = record.DateTimeNum;
    	    else if (record.ST < 3 && lastRecord.ST >= 3)
            {
                if (startDateNum != null)
                {
                    var eventStartDate = startDateNum.HasValue ? new DateTimeOffset?(DateTime.FromOADate(startDateNum.Value)) : null,
                    var newEvent
                            = new StationEvent
                            {
                                StationTableName = stationTableName,
                                StartOADate = startDateNum.Value,                                            
                                EndOADate = stationType.ToString() == "BBM" && eventStartDate >= SEDateTime ? record.DateTimeNum : lastRecord.DateTimeNum
                            };
                    yield return newEvent;
                }
    
                startDateNum = (Double?)null;
            }
    } 
       

    Hello All,

    I have the above code and I am getting this error:

    " Cannot use more than one type in a for, using, fixed, or declaration statement"

    The error is at this line.

     EndOADate = stationType.ToString() == "BMP" && eventStartDate >= SEDateTime ? record.DateTimeNum : lastRecord.DateTimeNum

    How should I do this?

    Monday, September 29, 2014 4:59 PM

Answers

  • User265788195 posted

    Oops, It was just one typo which I didn't realize..

    var eventStartDate = startDateNum.HasValue ? new DateTimeOffset?(DateTime.FromOADate(startDateNum.Value)) : null,

    The comma at the end was the problem, because of the error I thought something must be really wrong..
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 30, 2014 1:33 PM

All replies

  • User-760709272 posted

    Try adding parenthesis

    EndOADate = (stationType.ToString() == "BBM" && eventStartDate >= SEDateTime) ? record.DateTimeNum : lastRecord.DateTimeNum
    
    

    Monday, September 29, 2014 5:56 PM
  • User265788195 posted

    Oops, It was just one typo which I didn't realize..

    var eventStartDate = startDateNum.HasValue ? new DateTimeOffset?(DateTime.FromOADate(startDateNum.Value)) : null,

    The comma at the end was the problem, because of the error I thought something must be really wrong..
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 30, 2014 1:33 PM