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 155093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T10:05:41+00:00 2026-05-11T10:05:41+00:00

I know this sounded stupid. But I gotta be doing something wrong here. Say,

  • 0

I know this sounded stupid. But I gotta be doing something wrong here.

Say,

struct lala {     private bool state1;      public lala(bool state1)     {         this.state1 = state1;     }      public void SetState1ToTrue()     {         this.state1 = true;     }      public bool GetState1()     {         return this.state1;     } } 

Then somewhere…

List<lala> lalas = new List<lala>();  lalas.Add(new lala(false)); lalas.Add(new lala(false));  lalas[0].SetState1ToTrue();  // Why is it False??? Console.WriteLine(lalas[0].GetState1()); 

Are there any workarounds to this except changing it to:

List<lala> lalas = new List<lala>();  lalas.Add(new lala(false)); lalas.Add(new lala(false));  lala newLala = lalas[0]; newLala.SetState1ToTrue(); lalas[0] = newLala;  // It's True, finally. Console.WriteLine(lalas[0].GetState1()); 

Which looked awful, unelegant and wasted 2 lines of code. If there’s any Linq-ish or Functional Programming-ish way in say 1 line of code that would be awesome.

  • 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. 2026-05-11T10:05:41+00:00Added an answer on May 11, 2026 at 10:05 am

    The problem is in this line:

    lalas[0].SetState1ToTrue(); 

    The first part, lalas[0], retrieves the first lala from the list, and does so as a new copy of it in an implicit variable. So your SetState1ToTrue operates on a lala that is then immediately discarded, and the one in the list remains the same. It’s the same as doing this:

    lala newLala = lalas[0]; newLala.SetState1ToTrue(); 

    If you make lala a class not a struct, so that it becomes a reference type, then the temporary variable (explicit or implicit) is a reference to the lala within the list.

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

Sidebar

Related Questions

I know this is a stupid question, but I've looked for 45 mins now
I know this is normally rather stupid, but don't shoot me before reading the
I know this is a classic interview question, but here is my quick attempt
I know this is so basic, but for some reason it's just not doing
I know this question would have been asked several time but still I am
I know this question has been asked numerous number of times, both here and
I had a look at this and this but no one sounded particularly sure
I know this is a very simple question for you experts,but please forgive me.Im
I know this is a minor issue, but why, if you use scaffolding in
I know this is very trivial but I can't seem to find the answer

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.