I'm very new to Linq and having a problem with this code:
double[] values;
private List<double[]> valueList = new List<double[]>();
void AddNewValues(double d1, double d2, double d3)
{
values[0] = d1;
values[1] = d1;
values[2] = d1;
valueList.Add(values);
}
void GetAllFirstValues()
{
var test = valueList.Where(s => s == typeof(double[0]));
}
How to get the first item of each array inside the list?
Is that even possible? Is Linq here a proper way to do that or is there a more clever solution?
var test = valueList.Where(s => s == typeof(double[0])).FirstOrDefault();typeof(double[0])and nots.First()? Why you usetypeofat all? UsevalueList.Select(s => s.First())typeof(double[0])is not valid syntax, the checks == typeof(double[])will never be true in the above example.sis an double array value, whiletypeof(double[])would return the Type. If you want to check if it is a double array you'll needs.GetType() == typeof(double[])or with pattern matchings is double[]. However, this is unneeded in your code as the List is typed to a double[].