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 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

Ask A Question

Stats

  • Questions 75k
  • Answers 75k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Lump in #apache on freenode helped me out. RewriteCond %{HTTP_HOST}… May 11, 2026 at 2:37 pm
  • added an answer If your customer uses active directory already, then you can… May 11, 2026 at 2:37 pm
  • added an answer What am I doing to myself? Getting yourself all het… May 11, 2026 at 2:37 pm

Related Questions

We are an all Unix shop (Solaris, Linux). This last product cycle I returned
Currently I am developing a site with about seven partial classes, a few icons,
This caught my attention last night. On the latest ALT.NET Podcast Scott Bellware discusses
I have several sources of tables with personal data, like this: SOURCE 1 ID,

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.