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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:09:40+00:00 2026-05-18T21:09:40+00:00

I have a two-dimensional char array declared with four strings. private static string string1

  • 0

I have a two-dimensional char array declared with four strings.

private static string string1 = "abcde";
private static string string2 = "ABCDE";
private static string string3 = "12345";
private static string string4 = "67890";

public string selectChars(bool includeOne, bool includeTwo, bool includeThree, bool includeFour)
{
   char[][] charGroups = new char[][] 
   {
       string1.ToCharArray(),
       string2.ToCharArray(),
       string3.ToCharArray(),
       string4.ToCharArray()
   };
}

I want to declare and initialize the array such that the string add is conditional based on four bool flags. For example, if includeOne and includeThree are true, I want to end up with a charGroup[2][5] having used string1 and string 3.

(This is existing code where I don’t want to radically change the rest of the code. if I can conditionally declare the array in that block, I’m done.)

  • 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-18T21:09:41+00:00Added an answer on May 18, 2026 at 9:09 pm

    The manner you want is like a list, so it’s better implement it by list and then return an array by ToArray:

    public string selectChars(bool includeOne, bool includeTwo, bool includeThree, bool includeFour)
    {
            List<char[]> chars = new List<char[]>();
            string string1 = "";
            if (includeOne)
                chars.Add(string1.ToCharArray());
            if(includeTwo) ....
    
            char[][] charGroups = chars.ToArray();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a two-dimensional array (of Strings) which make up my data table (of
I have a two dimensional array that I need to load data into. I
Inspired by Raymond Chen's post , say you have a 4x4 two dimensional array,
I have a 2 dimensional array, like so: char[,] str = new char[2,50]; Now,
i have following code for allocation two dimensional array #include <iostream> using namespace std;
I have a simple, two dimensional array like this: Array ( [0] => Array
I have a two-dimensional array of ints, for example: int [][] board= { {23,17,3,29,12,10},
I have a two dimensional array, i.e. an array of sequences which are also
I have a two dimensional array having elements of a matrix I want to
I have two dimensional float array as below {0.2,0.0,0.3,0.0,0.0} {0.4,0.1,0.0,0.0,0.9} {0.0,0.0,0.0,0.3,0.6} I want to

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.