console readline c

Here, take input from the user. Since age is an integer, we typecasted it using Convert.ToInt32() Method. It reads the next line from the input stream. It blocks until Enter key is pressed. Hence it is commonly used to pause the console so that the user can check the output.

// C# program to illustrate 
// the use of Console.ReadLine() 
using System; 
using System.IO; 
  
class GFG { 
      
    // Main Method 
    public static void Main() 
    { 
        int age; 
        string name; 
  
        Console.WriteLine("Enter your name: "); 
          
        // using the method 
        // typecasting not needed  
        // as ReadLine returns string 
        name = Console.ReadLine(); 
          
        Console.WriteLine("Enter your age: "); 
          
        // Converted string to int 
        age = Convert.ToInt32(Console.ReadLine()); 
          
        if (age >= 18)  
        { 
            Console.WriteLine("Hello " + name + "!"
                        + " You can vote"); 
        } 
        else { 
            Console.WriteLine("Hello " + name + "!"
                + " Sorry you can't vote"); 
        } 
    }  
} 

Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source