r3nder
asked on
get the first Item in a list linq
I am trying to get the first Item in a list and it keeps throwing an error on .Take(1) how can I get this to select the first column (thedepth) of 2 columns in a list called gammalist
int t2 = Convert.ToInt32(total);
for (int i = 0; t2 >= 100; i++)
{
int depthToRemove = Convert.ToInt32(Program.myMainControl.dtoc.gammaList.Where(g => g.theDepth).Take(1));
Program.myMainControl.dtoc.gammaList.RemoveAt(0);
gammaseries.DataPoints.RemoveAt(0);
dtg.Rows[0].Delete();
t2 = depthToRemove - t2;
}
What is the type of gammaList?
ASKER
public struct gammaPlots
{
public float thedepth { get; set; }
public float thegamma { get; set; }
}
public List<gammaPlots> gammaList = new List<gammaPlots>();
{
public float thedepth { get; set; }
public float thegamma { get; set; }
}
public List<gammaPlots> gammaList = new List<gammaPlots>();
Your problem is you are passing an IEnumerable<gammaPlots> to Convert.ToInt32. I assume you meant to send the first theDepth value. I think you should be using First instead:
int depthToRemove = Convert.ToInt32(Program.myMainControl.dtoc.gammaList.Where(g => g.theDepth).First().theDepth);
ASKER
error on g.thedepth
Cannot convert lambda expression to delegate type 'System.Func<SimplyMWDClie ntGen2.DTO .DTOClass. gammaPlots ,bool>' because some of the return types in the block are not implicitly convertible to the delegate return type
Connot implicitly convert type float to bool
Cannot convert lambda expression to delegate type 'System.Func<SimplyMWDClie
Connot implicitly convert type float to bool
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
var depthToRemove = Program.myMainControl.dtoc .gammaList .Where(g => g.thedepth >= 0.00).First().thedepth;
this gives me almost all the depths added together - I just want the first depth - what am I doing wrong - I don't see it
this gives me almost all the depths added together - I just want the first depth - what am I doing wrong - I don't see it
ASKER
Wait that is getting the depth - I need to do some math now
ASKER
Thanks Kaufmed