Link to home
Start Free TrialLog in
Avatar of r3nder
r3nderFlag for United States of America

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;
                        
                    }

Open in new window

Avatar of kaufmed
kaufmed
Flag of United States of America image

What is the type of gammaList?
Avatar of r3nder

ASKER

public struct 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);

Open in new window

Avatar of r3nder

ASKER

error on g.thedepth
Cannot convert lambda expression to delegate type 'System.Func<SimplyMWDClientGen2.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
ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of r3nder

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
Avatar of r3nder

ASKER

Wait that is getting the depth - I need to do some math now
Avatar of r3nder

ASKER

Thanks Kaufmed