You currently have JavaScript disabled on your browser.

This website uses JavaScript, and This page needs JavaScript activated to work correctly.

Please active JavaScript on your browser and then refresh this page.

adThumb

Sudoku Volume 10

$8.24      buyNow
Over 150 fun challenging sudoku puzzles (with answer sheets). Each puzzle is on its own page, which not only reduces crowding but also allows for larger word print sizes for easier reading. Answer sheets for each puzzle are provided in the back of the book. Fun for yourself and for the entire family. This makes for a great gift idea as well.

Input



C# provides a very easy-to-use method to quickly get console input from a user, by calling and using the .ReadLine() method.

The following example prompts the user and asks them for a value, which it then stores into a variable, and then outputs the value back to them:

 
// type your username and press enter
Console.WriteLine("Enter username:");

/*
Create a string variable, 
prompt user to get user input, 
and then store users value into the variable
*/
string userName = Console.ReadLine();

// Display the variable value back to the user to show what value they entered
Console.WriteLine("Username is: " + userName);

The full C# code for the above example is as follows:

 
using System;

namespace ThisApp
{
  class MainProgram
  {
    static void Main(string[] args)
    {
      // type your username and press enter
      Console.WriteLine("Enter username:");

      /*
      Create a string variable, 
      prompt user to get user input, 
      and then store users value into the variable
      */
      string userName = Console.ReadLine();

      // Display the variable value back to the user to show what value they entered
      Console.WriteLine("Username is: " + userName);
    }
  }
}

NOTE: The .ReadLine() method always returns a string type variable. Therefore, if you are attempting to get a numerical value from the user, you must CAST the string value into that desired data type (i.e. int) programmatically. Assigning the return value from .ReadLine() directly into an int variable will cause an error. To avoid the error, use the Convert.To methods on the returned value to CAST the value before assigning it to the variable (additional other error checking may also be required).



Final Thoughts

Thank you for reading, I hope you found this blog post (tutorial) educational and helpful.

 
(0)   (0)

grayStargrayStargrayStargrayStargrayStar  Be the first to rate this post

User Comments






TJDivisions© 2023