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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:09:30+00:00 2026-05-31T03:09:30+00:00

Right now I create following arrays (on Button_click event): string[,] Butt = new string[2,

  • 0

Right now I create following arrays (on Button_click event):

string[,] Butt = new string[2, 3] { 
                 { "120", "200", "#ffc90e" },
                 { "380", "200", "#22b14c" } 
               };

int[,] arrat = new int[,] {
                    { 199, 199 },
                   { 257, 189 },
                   { 407, 185 },
                   { 521, 196 },
                   { 608, 232 },
                   { 620, 300 },
                   { 509, 338 },
                   { 386, 344 },
                   { 288, 347 }
                  };

I want to optimize my code so I don’t have to crete new arrays each time. Better solution will be – to load arrays from file on program launch

lets say I have a CSV file with following content:

199, 199

257, 189

407, 185

521, 196

how do I load everything into an array: “int[,] array = new int[,]” ??

  • 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-31T03:09:31+00:00Added an answer on May 31, 2026 at 3:09 am

    You should put some error checking but you may start from:

    private static string[,] Parse(string path, int columnCount, char columnSeparator = ',')
    {
     string[] lines = File.ReadAllLines(path);
    
     string[,] result = new string[lines.Length, columnCount];
     for (int rowIndex = 0; rowIndex < lines.Length; ++rowIndex)
     {
      string[] columns = lines[rowIndex].Split(new char[] { columnSeparator }, columnCount);
    
      for (int columnIndex = 0; columnIndex < columns.Length; ++columnIndex)
       result[rowIndex, columnIndex] = columns[columnIndex];
     }
    
     return result;
    }
    

    Helper method for conversion (instead you may want to embed in the Parse() method):

    private int[,] ConvertToInt(string[,] matrix)
    {
     int[,] result = new int[matrix.GetLength(0), matrix.GetLength(1)];
     for (int i = 0; i < result.GetLength(0); ++i)
     {
      for (int j = 0; j < result.GetLength(1); ++j)
      {
       int value = 0;
       if (Int32.TryParse(matrix[i, j], System.Globalization.NumberStyles.Integer, CultureInfo.InvariantCulture, out value))
        result[i, j] = value;
      }
     }
    
     return result;
    }
    

    (I’m not using LINQ ’cause I guess you should put a lot of error checking inside that methods to validate input data).

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

Sidebar

Related Questions

Right now I'm trying to create my own tiny MVC (just for practice and
Right now I'm using JFreeChart in order to create a dynamic chart. However the
I have create my own NSOpenGLView class, right now the data that i want
I'm trying to create a faster query, right now i have large databases. My
I want to create an SQL script that creates a database. Right now, I
So I'm trying to create a forum with avatars, but right now the text
Right now my products model has a string column of category, with the form
I have done the following trying to create 2d and 3d arrays: Array1 =
I've created a custom view class and right now just want to draw an
I have created some tests in my WPF application. Right now I am working

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.