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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:39:58+00:00 2026-05-13T20:39:58+00:00

I want to resize my array dynamic. Everything would be ok, but in example

  • 0

I want to resize my array dynamic. Everything would be ok, but in example I find someone use Array.Resize() to resize one dimension array, but I want to have possibility create jagged array. I read from file line, in which it could be some numbers separate by space – therefore i need jagged array created dynamic.
It’s my class when i use it, but my array don’t resize 🙁

class Program
{
    int[][] nodesMatrix = null;
    private void ReadFromFile(string fileName)
    {

        string line;
        int nodesNr;

        if(File.Exists(fileName) )
        {
            StreamReader fileReader = null;
            try
            {
                fileReader = new StreamReader(fileName);
                int lineNr = 0;
                while ((line = fileReader.ReadLine()) != null)
                {
                   int connectionsNr = 0;
                    if (lineNr==0)
                    {
                        nodesNr = Convert.ToInt32(line);
                        nodesMatrix = new int[nodesNr][];
                        for (int i = 0; i < nodesNr;i++ )
                        {
                            nodesMatrix[i] = new int[1];
                        }
                    }
                    else
                    {

                        string tmpNumber = null;
                        foreach (char sign in line)
                        {

                            if (sign != ' ')
                            {

                                tmpNumber += sign;

                            }
                            if (sign == ' ')
                            {

                                if (tmpNumber != null)
                                {

                                    //nodesMatrix[lineNr] = new int[connectionsNr+1];
                                    nodesMatrix[lineNr][connectionsNr] = Convert.ToInt32(tmpNumber);
                                    connectionsNr++;
                                    Array.Resize<int>(ref nodesMatrix[lineNr], connectionsNr); //here i try to resize array                                      

                                }
                                tmpNumber = null;
                            }
                        }
                    }
                     lineNr++;
                }
            }
            finally
            {
                if (fileReader != null)
                    fileReader.Close();
            }
        }

Maybe You know how to do it ?

  • 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-13T20:39:59+00:00Added an answer on May 13, 2026 at 8:39 pm

    Maybe I’m not understanding your use case but it seems to me that if you have a data structure that you know will need to be resized, that it’s better to use a List or related structure, rather than an array. You can always convert the list back to an array at the end via the .ToArray() extension added by linq.

    Likewise, if you use generics, you can ensure that you have a strongly typed, multi-dimensional list. You could likewise use a pair of lists internally, and create your own class that wraps them both.

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

Sidebar

Ask A Question

Stats

  • Questions 386k
  • Answers 386k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Use preg_split() with an appropriate regex. May 14, 2026 at 11:42 pm
  • Editorial Team
    Editorial Team added an answer I used the jquery plugin validate and using that I… May 14, 2026 at 11:42 pm
  • Editorial Team
    Editorial Team added an answer In Info.plist, set UIInterfaceOrientation to UIInterfaceOrientationLandscapeRight (or Left). See the… May 14, 2026 at 11:42 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.