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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:26:27+00:00 2026-06-11T16:26:27+00:00

I am currently working with storing data into arrays. The program takes the information

  • 0

I am currently working with storing data into arrays. The program takes the information from a text files and then formats the result with product name. The issues is that if other than a number(int) is found in the starting line of the text the file breaks. Specifically at productID = Convert.ToInt16(storeData[0]);. How can I avoid breaking the program if the first character in the text file is other than an integer?

how the info looks in the text file: ProductID, Month and Sales

1 5 20.00

CODE

string[] productName = new string[100];
                string arrayLine;
                int[] count = new int[100];
                int productID = 0;
                double individualSales = 0;
                double[] totalSales = new double[100];
                double[] totalAverage = new double[100];

                productName[1] = "Cookies";
                productName[2] = "Cake";
                productName[3] = "Bread";
                productName[4] = "Soda";
                productName[5] = "Soup";
                productName[99] = "Other";                                      

                while ((arrayLine = infile.ReadLine()) != null)
                {


                    string[] storeData = arrayLine.Split(' ');

                    productID = Convert.ToInt16(storeData[0]);
                    individualSales = Convert.ToDouble(storeData[2]);

                    if (stateName[productID] != null)
                    {
                        count[productID] += 1;
                        totalSales[stateID] += individualSales;
                    }
                    else
                    {
                        count[99] += 1;
                        totalSales[99] += individualSales;
                    }


                }
                infile.Close();
  • 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-11T16:26:29+00:00Added an answer on June 11, 2026 at 4:26 pm
    if (!Int16.TryParse(storeData[0], out productID))
       continue;//or do something else
    

    Int16.TryParse

    as Gromer stated, I’d rather use int.TryParse (which is in fact Int32.TryParse)…

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

Sidebar

Related Questions

I'm currently working on a program to generate the hashes of files, in Delphi
I'm currently working on encryption/decryption of plain text files that are embedded in a
Currently I'm working on a program that parses through a file and takes characters
I'm currently working on a Silverlight app and need to convert XML data into
Currently working with converting SQLException error messages into messages that are more useful for
Currently working with the following package structure: /package __init__.py final.py /write __init__.py write.py /data
I'm currently working on a project where we have a large data warehouse which
The system I am currently working on uses Stored Procedures for all data access.
Currently I'm working off of a data set which is just redicolus; a flat
I am trying to read in data from a text file (the time). and

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.