Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
SolvedPrivate

get the first Item in a list linq

Posted on 2014-04-22
8
Medium Priority
?
78 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 your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
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 2000 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

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

722 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