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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:13:14+00:00 2026-06-01T01:13:14+00:00

I am trying to hold integer inputs into an array but it doesn’t work.

  • 0

I am trying to hold integer inputs into an array but it doesn’t work. I found an example for string hold from How to Fill an array from user input C#?

string[] yazi = new string[15];
for (int i = 0; i < yazi.Length; i++)
{
      yazi[i] = Console.ReadLine();
}

But when I turn this code to integer, it gave an error

int[] sayis = new int[20];
for (int k = 0; k < sayis.Length; k++)
{
      sayis[k] = int.Parse(Console.ReadLine());
}

Am I missing something?

  • 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-01T01:13:16+00:00Added an answer on June 1, 2026 at 1:13 am

    Am I miss something?

    The error message, for one thing…

    It should be fine – so long as you type integers into the console. (I’ve just tried it, and it worked perfectly.) If the user enters a value which can’t be parsed as an integer, you’ll get a FormatException. You should consider using int.TryParse instead… that will set the value in an out parameter, and return whether or not it actually succeeded. For example:

    for (int k = 0; k < sayis.Length; k++)
    {
        string line = Console.ReadLine();
        if (!int.TryParse(line, out sayis[k]))
        {
            Console.WriteLine("Couldn't parse {0} - please enter integers", line);
            k--; // Go round again for this index
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i was trying to hold an image into a string (png) then i was
I'm trying to make an array of integers in java but it won't work
I'm trying to use an array to hold inputs for a survey that will
I'm trying to get a hold of the data returned from getJSON, but I
I'm trying to create an array which will hold the hours in a day
I'm trying to cache a price value using HttpRuntime.Cache.Insert(), but only appears to hold
I am trying to create a database to hold my address book but I've
I am trying to hold on to the information from a form after the
I'm trying to get hold of data from a NSXMLParser I have the following
I'm trying to get hold of the querystring directly from the template in Umbraco,

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.