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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:37:36+00:00 2026-06-15T13:37:36+00:00

Possible Duplicate: printing 2d array in c# through for loop this is how my

  • 0

Possible Duplicate:
printing 2d array in c# through for loop

this is how my data in txt file:

1--2--3--    
3-4-4-5--    
-7-3-4---
7--5--3-6    
--7---4--    
3-2--4-5-    
------3--    
2-6--7---    
4---4--3-

without any empty line between! have this formatting issue above!

is my c# code to do file reading with the display too:

public void populate_grid_by_file()
        {
            int counter = 0;
            string line;

            // Read the file and display it line by line.
            System.IO.StreamReader file =
               new System.IO.StreamReader("data.txt");
            for (int i = 0; i < Sodoku_Gri.GetLength(0); i++)
            {
                while ((line = file.ReadLine()) != null)
                {
                    for (int j = 0; j < Sodoku_Gri.GetLength(1); j++)
                    {
                        Sodoku_Gri[i,j] = line[j];
                        Console.Write(line[j].ToString());

                    }
                    Console.WriteLine(line);
                    counter++;
                }
            }
            file.Close();
            // Suspend the screen.
            Console.ReadLine();
        }   

but when i display my array with the file reading above it is like:

1--2--3--1--2--3--    
3-4-4-5--3-4-4-5--    
-7-3-4----7-3-4---    
7--5--3-67--5--3-6    
--7---4----7---4--    
3-2--4-5-3-2--4-5-    
------3--------3--    
2-6--7---2-6--7---    
4---4--3-4---4--3-

cnt understand why duplication! help!

When i debugged i found that there was a problem in the line:

Console.Write(line[j].ToString());

it means that automatically elements are not being loaded into the array here:

Sodoku_Gri[i,j] = line[j];

Kindly help me with this!

  • 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-06-15T13:37:37+00:00Added an answer on June 15, 2026 at 1:37 pm

    You display the line once, character by character here:

        Console.Write(line[j].ToString());
    

    And then the full line all at once here:

         Console.WriteLine(line);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Reading a .doc (MSWord) file in ObjectiveC? I am writing a printing
Possible Duplicate: Printing of Array public function computeGHComponents() { error_reporting (E_ALL^ E_NOTICE); $total =
Possible Duplicate: Printing without newline (print 'a',) prints a space, how to remove? I
Possible Duplicate: Creating, opening and printing a word file from C++ Hi, I need
Possible Duplicate: Printing message on Console without using main() method Can someone suggest how
Possible Duplicate: How to find the sizeof(a pointer pointing to an array) Sizeof array
Possible Duplicate: Printing Table's structure/schema oracle has 'DESCRIBE' to get all the details of
Possible Duplicate: C printing bits Lets say I have a uint16_t number something like:
Possible Duplicate: C++ alignment when printing cout << I am writing a set of
Possible Duplicate: How can I convert a list<> to a multi-dimensional array? I want

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.