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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T16:56:39+00:00 2026-05-20T16:56:39+00:00

I am trying to make a 1d array of lists. I make it like

  • 0

I am trying to make a 1d array of lists. I make it like this:

public static List<string>[] words = new List<string>[30];
public static List<string>[] hints = new List<string>[30];

And I call it like this:

foreach (string item in vars.directory)
        {
            reader2 = new StreamReader(item);
            while (reader2.Peek() > 0)
            {
                string line = reader2.ReadLine();
                if (line.StartsWith("#"))
                {
                    vars.words[counter].Add(line.Substring(1, line.Length - 1)); //here
                }
                else if (line.StartsWith("-"))
                {
                    vars.hints[counter].Add(line.Substring(1, line.Length - 1)); //another here
                }
                else if (line == "@end")
                {
                    counter++;
                }
            }
        }

I just wanted to add that vars is where I keep my public variables and that counter is indeed at 0 when the loop starts.

EDIT
In my haste I forgot to add the question… oops…

Here it is: When I call the add function (or any another function for that matter) it returns a null reference exception. How can I fix this?

  • 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-05-20T16:56:40+00:00Added an answer on May 20, 2026 at 4:56 pm

    I assume you’re crashing when attempting to call .Add on your array element. You need to initialize your arrays with valid objects.

    for( Int32 i = 0; i < vars.words.Length; ++i )
      vars.words[i] = new List<string>();
    for( Int32 i = 0; i < vars.hints.Length; ++i )
      vars.hints[i] = new List<string>();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make a list containing different objects. List<Object> list = new ArrayList<Object>();
Trying to make a web service call to an HTTPS endpoint in my Silverlight
I'm programming a short Paint program like and I'm trying to make an MDI
I've managed to make some single dimension array lists but I can't figure out
Extending a previous question about JavaScript and jQuery, I'm trying to make an array
Trying to make a make generic select control that I can dynamically add elements
Trying to make a MySQL-based application support MS SQL, I ran into the following
Trying to make a generic PL/SQL procedure to export data in specific XML format,
I'm trying to make the case for click-once and smart client development but my
I'm trying to make a data bound column invisible after data binding, because it

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.