Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8650951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:56:38+00:00 2026-06-12T13:56:38+00:00

First off, I’m just starting to mess around with LINQ, and I don’t really

  • 0

First off, I’m just starting to mess around with LINQ, and I don’t really understand it.

Anyways, what I’m trying to do is add to a List with LINQ and the .Where statement.

This is what I’ve tried:

List<object> FirstList = new List<object>();
List<object> SecondList = new List<object>();
Listener.Clients.Where(x => (x.Value.Authenticated) ? FirstList.Add(x.Value.UserID) : SecondList.Add(x.Value.UserID));

Listener is a socket wrapper class, and Clients is an array of a class, Client.

In that Client class there are a few values that I need, and I want to check if that client is authenticated (logged in), and if it is, add it to the first list, and if it’s not, add it to the second list, however it seems that the ?: operator must have a return value, but adding to a list does not return anything.

I hope I explained that good; I’m not the best with words.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T13:56:40+00:00Added an answer on June 12, 2026 at 1:56 pm

    You are trying to create two (or more) lists with one enumeration. Consider using ToLookup instead:

    ILookup<bool, Client> lookup = source.ToLookup(c => c.Value.Authenticated);
    List<Client> firstList = lookup[true].ToList();
    List<Client> secondList = lookup[false].ToList();
    

    When an unknown key is sent to the lookup, it will return an empty collection.


    You want UserIds instead of Clients, so use the overload of ToLookup that selects values.

    ILookup<bool, string> lookup = source
      .ToLookup(c => c.Value.Authenticated, c => c.Value.UserId);
    List<string> firstList = lookup[true].ToList();
    List<string> secondList = lookup[false].ToList();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First off, I would like to say that I am just starting with PHP
First off: I hate Outlook :) Here is why: I am trying to send
First off, I'm a real beginer at C# so please be gentle. I'm trying
First off, I would just like to mention my absolute hatred of Internet Explorer
First off, I'm new to Scala. I'm trying to make a template parser in
First off I don't know much about regex and need to buy a book
First off, I think I'm trying to use Spring incorrectly, but confirmation would be
First off, does anyone have a comprehensive list of the Perl special variables? Second,
First off im very new to C# im trying to recreate a application i
First off, just wanted to say I'm a novice at this type of coding,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.