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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:48:14+00:00 2026-06-06T19:48:14+00:00

Is it possible to store a Class that contains a List inside an array?

  • 0

Is it possible to store a Class that contains a List inside an array?

I am having some trouble with this concept.

Here’s my code:

My Class Called “arrayItems”:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EngineTest
{
    [Serializable] //List olarak save etmemiz için bu gerekli.
    public class arrayItems
    {
        public List<items> items = new List<items>();
    }
}

Here’s the definition of my Array called “tileItems”:

 public static arrayItems[, ,] tileItems;

Here’s how I create my Array:

    Program.tileItems = new arrayItems[Program.newMapWidth, Program.newMapHeight, Program.newMapLayers];

The problem I am facing is that the content of my Array is null.
And I am getting this error:

Object reference not set to an instance of an object.

When I try to populate the List inside the array by Add() command I get the same error.

Can you direct me to the right direction please?
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-06T19:48:17+00:00Added an answer on June 6, 2026 at 7:48 pm

    Since you are already initializing the list within the class definition you do not need to re-initialize the list property of arrayItems within the loop.

    You have an array that has a bunch of pointers that point to nothing. So you actually need to instiante a new arrayItems in each array element first.

    for (int i = 0; i < newMapWidth; i++)
    {
        for (int j = 0; j < newMapHeight; j++)
        {
            for (int k = 0; k < newMapLayers; k++)
            {
                arrayItems[i,j,k]= new arrayitem();
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to store a NaN in a property list file. I tried:
Is it possible to store soemthing like this in a php string: $variable =
Is it possible to store the display list data on the video card memory?
Is it possible to store the credentials that I use to connect to my
I'm trying to set up a class so that it's possible to initialize it
I'm creating a class that will store data in a file and I need
Here's the question first: Is this possible? I'm taking my inspiration from Joe Wrobel's
This is a common problem for me. I have a solution that contains a
How are virtual functions implemented in position-independent code? I know that if my class
ok, first of all, I know this is not possible with 1.2., that is

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.