SolvedPrivate

get the first Item in a list linq

Posted on 2014-04-22
8
76 Views
Last Modified: 2016-02-16
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

0
Comment
Question by:r3nder
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40016122
What is the type of gammaList?
0
 
LVL 6

Author Comment

by:r3nder
ID: 40016132
public struct gammaPlots
        {
            public float thedepth { get; set; }
            public float thegamma { get; set; }
        }
public List<gammaPlots> gammaList = new List<gammaPlots>();
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40016144
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

0
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
LVL 6

Author Comment

by:r3nder
ID: 40016166
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
0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 40016169
Ah, I didn't notice this before, but your Where clause is incomplete. The thing you pass to Where should yield a boolean result.

e.g.

Where(g => g.theDepth > 3.00)

Open in new window


You need to tweak your Where to accommodate such.
0
 
LVL 6

Author Comment

by:r3nder
ID: 40016277
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
0
 
LVL 6

Author Comment

by:r3nder
ID: 40016285
Wait that is getting the depth - I need to do some math now
0
 
LVL 6

Author Closing Comment

by:r3nder
ID: 40016287
Thanks Kaufmed
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question