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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:48:18+00:00 2026-05-15T19:48:18+00:00

I am running the following code on an ASP.NET razor page (cshtml) and am

  • 0

I am running the following code on an ASP.NET razor page (cshtml) and am suffering the dreaded “Object reference not set to an instance of an object” problem. Could someone help me out with this problem? The code I’m using is below and the line causing the problem is menu[1][0] = "About";

string[][] menu = new string[5][];
menu[0] = new string[2];
// First menu item
menu[0][0] = "Home";
// First menu URL
menu[0][1] = "#";
// Second menu item
menu[1][0] = "About";
// Second menu URL
menu[1][1] = "#";
// Third menu item
menu[2][0] = "Contact";
// Third menu URL
menu[2][1] = "#";
// Fourth menu item
menu[3][0] = "More Info";
// Fourth menu URL
menu[3][1] = "#";
// Fifth menu item
menu[4][0] = "Test";
// Fifth menu URL
menu[4][1] = "#";

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-05-15T19:48:19+00:00Added an answer on May 15, 2026 at 7:48 pm

    You have only initialized the first element in menu. Try a for loop:

    for (int i = 0; i < menu.Length; ++i)
    {
        menu[i] = new string[2];
    }
    

    Alternatively you could write it like this:

    string[][] menu =
    {
        new string[] {"Home", "#"},
        new string[] {"About", "#"},
        new string[] {"Contact", "#"},
        new string[] {"More Info", "#"},
        new string[] {"Test", "#"}
    };
    

    Or use a rectangular array instead:

    string[,] menu =
    {
        {"Home", "#"},
        {"About", "#"},
        {"Contact", "#"},
        {"More Info", "#"},
        {"Test", "#"}
    };
    

    And since your second element is constant perhaps you don’t need to store it at all – in this case you could just use a string[].

    string[] menu = { "Home", "About", "Contact", "More Info", "Test" };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm getting an error when running the following code thru an ASP/ C# .NET
When I tried running the following code product([1,2,3],['a','b']) it returned an object of the
I am opening the msgbox in asp.net by following code.. if (ds.Tables[0].Rows[0][12].ToString() == 0
In my ASP.NET application, a while down the stack I call the following code:
I am working on an ASP.NET page that we, in code impersonate the requesting
We are running a silverlight asp.net appliction and we get the following error: Line:
I'm learning ASP.NET MVC 3 with Entity Framework Code First. I'm following a tutorial
running asp.net mvc website that has code that connects to oracle. Works fine on
I have an ASP.NET page running in SSL and the checking happens in the
I'm getting the following error in my ASP.NET web application in IIS when running

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.