I am trying to override the median value of a object EducationData, The model definition is as follows,
// EducationData model
[DataMember(Name = "DegreeConferred", Order = 1)]
public int DegreeConferred { get; set; }
[DataMember(Name = "NoOfInstitutions", Order = 3)]
public int NoOfInstitutions { get; set; }
[DataMember(Name = "Mean", Order = 6)]
public int Mean { get; set; }
[DataMember(Name = "Median", Order = 7)]
public IEnumerable<double> Median { get; set; }
CachedData is of type var, contains the ES query results of the education details as in the picture attached.
I have to override that median value with some alterations. Code segment I tried is as follows.
var resultData = cachedData.ToArray();
resultData[0].Mean = resultData[0].DegreeConferred / resultData[0].NoOfInstitutions; // calculated mean with no error
var updatedMedian = 7; // say for sample, because there is a need to override this queried value with some modification.
resultData[0].Median = updatedMedian; // Error line: Cannot implicitly convert type 'int' to 'System.Collections.Generic.IEnumerable<double>'
Please Note: Changing the property to int in the model will affect the implementation in further places. So it will be better to do casting here.
I tried with ReSharper suggestion, like, but nothing works
resultData[0].Median = Convert.ToDouble(updatedMedian);
resultData[0].Median = IEnumerable<double>updatedMedian;
Also changing the property of updatedMedian will affect the calculation steps.
I have also tried some of the suggestion of SO as,
- LINQ: Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<int>' to 'int'
- Linq Query : Cannot convert type IEnumerable<string> to string changing .ToString() to (string)
- Cannot implicitly convert type 'System.Collections.Generic.IEnumerable
I am struggling with this for past one and half days. Any suggestion would be very helpful.