SolvedPrivate

get the first Item in a list linq

Posted on 2014-04-22
8
69 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
  • 5
  • 3
8 Comments
 
LVL 74

Expert Comment

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

Author Comment

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

Expert Comment

by:käµfm³d 👽
Comment Utility
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
 
LVL 6

Author Comment

by:r3nder
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 74

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Wait that is getting the depth - I need to do some math now
0
 
LVL 6

Author Closing Comment

by:r3nder
Comment Utility
Thanks Kaufmed
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
VB6 Compile Compatibility Issue 4 23
crm development 2 34
Check if number is currency 15 27
What .NET website keeps me current? 9 28
A short article about problems I had with the new location API and permissions in Marshmallow
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…
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
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 …

762 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now