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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:19:22+00:00 2026-05-30T09:19:22+00:00

I am attempting to iterate over a 2d string array but my foreach statement

  • 0

I am attempting to iterate over a 2d string array but my foreach statement has a compile error that I dont understand.

What am I doing wrong in this simple example & how can I perform what I am trying to do?

string URL = PRODUCT_URL + "?";

string[,] a = {{"a","1"},{"b","2"}};
foreach (string[] param in a)    // error cannot convert type string to string[]
{
    URL += param[0] + "=" + param[1] + "&";
}
  • 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-30T09:19:23+00:00Added an answer on May 30, 2026 at 9:19 am

    C# has two similar constructs, Arrays of arrays and multidimensional arrays. What you have here is a 2 dimensional array, so the loop you want is

    foreach (string param in a)
    {
    ...
    }
    

    If you wanted to go the array of arrays approach, you’d want:

    string[][] a = {new[] {"a","1"}, new[] {"b","2"}}
    

    for your declaration.
    Internally, C# implements the multidimensional array as a normal array with a size equal to the product of the dimension (e.g. since your a is 2×2, it would be a linear array of length 4). This way, the programmer can use a more convenient syntax for member access and initialization.

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

Sidebar

Related Questions

When attempting to compile my C# project, I get the following error: 'C:\Documents and
When attempting to understand how a SQL statement is executing, it is sometimes recommended
I'm attempting to iterate over the ListViewDataItems in an ASP.Net ListView, and use the
Attempting to print out a list of values from 2 different variables that are
Attempting to make a NSObject called 'Person' that will hold the login details for
I am attempting to load up an entire array of NSManagedObjects into an NSArray,
I'm attempting upload multiple files in ASP.NET MVC and I have this simple foreach
I'm attempting to iterate through a response from a jQuery Ajax request (returned as
I am attempting to generate map overlay images that would assist in identifying hot-spots,
I am looking to iterate over a group of divs and perform some random

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.