Information on the Where keyword.
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Information on the Where keyword.

  1. #1
    Join Date
    Jul 2013
    Posts
    4

    Information on the Where keyword.

    I've only been doing C# for a few days, and I'm working on a simple console application. The user can insert details to create elements, edit elements, delete elements, and now sort them. /edit - This is going to make a colon delimited file that will be used in a future project.

    I have no formal education on C#, or object oriented programming, so I apologize if this seems elementary. I browsed the internet, looking at how to sort a List<T> full of element objects based on a certain field. I found the answer, and once adapted, here it is:

    Code:
    foreach (Element o in elementList.Where(Element => Element.gAtomicNumber == Convert.ToInt32(str)).ToArray())
                 {
                      elementList.Remove(o);
                 }
    What is the '.Where' keyword? Does anyone have any links to information on this? It seems very convenient and I would like to learn more about it if possible.

    Thanks for any advice!

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,359

    Re: Information on the Where keyword.

    A good source of online documentation is the MSDN (Microsoft Development Network) Library. If you aren't familar with the site, I suggest you bookmark it.

    Another good source of info is doing a bing or google search. The hard part when you first start out is knowing which words to search for.

    Since I've been around for a little while, I know that the where clause is used in (at least) two places in C# code: 1) in a LINQ expression, and 2) in a generic constraint. Looking at your code, I know see that it's LINQ, so I searched bing for "LINQ where clause C#".

    This gave me several hits, including this one from MSDN:
    where clause (C# Reference)

    Feel free to post questions, but always try to look in msdn and do a general internet search first. That way, why you learn your programming skills, your googling and research skills will improve as well, and before you know it, you'll be on forums answering questions.

  3. #3
    Join Date
    Jul 2013
    Posts
    4

    Re: Information on the Where keyword.

    Yeah, I had scavaged MSDN but, I could only find the where contextual keyword, I had no idea what LINQ so not knowing what LINQ is/was hampered how to find it. Thank you for your response.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center