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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:30:32+00:00 2026-06-14T09:30:32+00:00

I have an object I create and stick in a collection: public class Level

  • 0

I have an object I create and stick in a collection:

public class Level
{
    private string id;

    private List<LevelTypes> usableLevelTypes;  // LevelTypes is an enum
    private List<BlockTypes> levelMapping;      // BlockTypes is also an enum

    public Level(string id, List<LevelTypes> levelTypes, List<BlockTypes> incomingBlocks)
    {
        this.id = id;
        this.usableLevelTypes = levelTypes

        levelMapping = incomingBlocks;
    }

Stepping through this, I can see each item being set properly. The object is then placed in a HashSet.

Another class then iterates through the HashSet calling each item’s overloaded .ToString() method.

At this point I have all relevant variables in this class on my watch list. Everything within the object called is set properly. “id”, “levelMapping” and all other variables that I have not listed including other List<T>‘s and int’s contain their proper values except “usableLevelTypes”, which is reported as being empty.

public override string ToString()
{
    var s = new StringBuilder();

    s.Append("ID: " + id);
    s.Append(" Level Types: " + usableLevelTypes[0].ToString()); // At this point,
    // this list should have at minimum one value in it.  However, it is empty and
    // will throw an exception stating as much.

    return s.ToString();
}

At no point is .Clear() called on the usableLevelTypes List and it is read-only. How could it be reset when other lists within the same object are not?

  • 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-14T09:30:34+00:00Added an answer on June 14, 2026 at 9:30 am

    You are not creating a copy of the list that you pass in to the Level constructor for usableLevelTypes. So whatever is happening to that outer list is going to happen to the list inside Level. Without seeing the calling code, I cannot tell you specifically what the problem is.

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

Sidebar

Related Questions

Suppose we have a class. We create an object from the class and when
Currently I have this code var App = Ember.Application.create(); App.user = Ember.Object.create({ people: customers
I have this object I'm loading with THREE.objLoader and then create a mesh with
So I have an object of ArrayProxy kind var App = Ember.Application.create(); App.car =
I have an object Student with 4 attributes(age,name,department,surname). and I create an array of
I have a Rect object that I'd like to create and set its properties
I have function some_func_1 which will create an object of type some_type and will
I want to have one directory for all object files and create Common.pri file
I have a collection of objects which I pass as parameter to create objects
I have what should be very simple. I create a new collection, and I

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.