8
Contributors
12
Replies
55
Views
10 Years
Discussion Span
Last Post by ddanbe
Featured Replies
  • [quote=campkev;311967]int intTemp = Convert.ToInt32(Console.Readline())[/quote] i have also found one other way that is int n= int.Parse(Console.ReadLine()); thanks pal that is great Read More

0

maybe this short tutorial will help you. Follow the link near the bottom of the page for other tutorials.

that link is telling how to read from a file I want to know how to read from keyboard.
Like we have have cin command in c++ and scanf in C

0

If your using a Console app it should be

string strTemp = Console.Readline()

but i said i wanted to read integer tht will read integer as character

1

int intTemp = Convert.ToInt32(Console.Readline())

i have also found one other way that is
int n= int.Parse(Console.ReadLine());
thanks pal that is great

0

Crap forgot that he wanted a integer and not a string. :)

no prob it is done now thanks for answering;)

0

hey these codes are working you can debug and use
int sum = 7;
Console.WriteLine("enter an integer for adding");

int a = int.Parse(Console.ReadLine());

sum += a;

Console.WriteLine(sum);

0

must given input in integer without string..how is it possible in c#?suppose user given input in string how can i manage?

0

Hi Jeya Rani, welcome to DaniWeb.
First: Don't resurrect old threads.
Start a new thread with your question and refer to this thread with a link, if you want to.
To answer you question, try this:

        /// <summary>
        /// Read an integer from the console
        /// Return 0 if no success(perhaps MaxInt?)
        /// </summary>
        /// <param name="prompt">descriptive message</param>
        /// <returns>an integer</returns>
        public int readInt(string prompt)
        {
            Console.Write(prompt);
            string line = Console.ReadLine();
            int quantity;
            if (int.TryParse(line, out quantity) == false)
            {
                quantity = 0;
            }
            return quantity;
        }
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.