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

  • SEARCH
  • Home
  • 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 8002399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:21:13+00:00 2026-06-04T16:21:13+00:00

I am trying to access a user object in a collection with the id

  • 0

I am trying to access a user object in a collection with the id = to users101 and set this to another users.

Controller.MyObject.SingleOrDefault(x => x.Id == "user101") = OtherUser();

Thanks in advance.

  • 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-04T16:21:15+00:00Added an answer on June 4, 2026 at 4:21 pm

    You can’t do it with one LINQ expression.

    Usually LINQ extensions works on enumerables, if MyObject is a collection you first have to find the required item and then overwrite it with the new object (moreover SingleOrDefault() will simply return null if condition is not satisfied).

    You should write something like this (exact code depends on what MyObject is):

    var item = Controller.MyObject.SingleOrDefault(x => x.Id == "user101");
    if (item != null)
        Controller.MyObject[Controller.MyObject.IndexOf(item)] = new OtherUser();
    

    Please note that if you do not really need the check performed by SingleOrDefault() you can simplify the code (and avoid the double search performed in SingleOrDefault() and IndexOf()).

    If this is “performance critical” maybe it is better to write an ad-hoc implementation that does this task in one single pass.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get access to the user agent with Flask, but I either
I am trying to find a good pattern to use for user access validation.
Is it best to check for a null User when trying to access UserID
In my windows form application, I'm trying to test the user's ability to access
Im trying to access the Magento customer session in another part of my website.
I'm trying to access third party api which gives me object and sub object,
Is it possible to pull a user object from any controller? For me it
I am trying to access data from a javascript object in order to dynamically
I'm trying to store Twitter access token to my database for a specific user,
Trying to access a Servlet from a button on HTML page //Html Page FORM

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.