Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Taking input from the User | Introduction
Introduction to .NET with C#
course content

Contenido del Curso

Introduction to .NET with C#

Introduction to .NET with C#

1. Introduction
2. Asynchronous Programming and Introduction to Web Services
3. Introduction to Databases with .NET
4. CRUD Operations with MySQL
5. Optimizing Database Operations

bookTaking input from the User

Recap:

  • Console.ReadLine() statement can be used for taking input from the user, in the form of a string;
  • Every built-in data type has a Parse method. It can be used for extracting data of that type from a string;
  • Giving a value of a very big magnitude (can be positive or negative) for int.Parse will crash the program. This happens because int has a limited capacity, and if the number is bigger than that capacity, the program doesn't know what to do, so it crashes. In cases where values of big magnitude are expected, using long.Parse is preferable;
  • Using float.Parse when dealing with very precise values can potentially cause loss of data because float has a limited precision, and parsing a very precise value will cause the program to round off the input - therefore causing some loss of precision/data. It is preferable to use double.Parse in such cases;
  • A character can be parsed from a string using the char.Parse() method. It can also be parsed via indexing as well. So using Console.ReadLine()[0] is a shorter way of writing char.Parse(Console.ReadLine()).
1. Which method is used for taking input from the user?
2. What is the type of returned data from the <code>Console.ReadLine()</code> method?
3. What will be the output of the following statement?
4. Assuming that the user enters an empty string as an input, what will be the output of the following statement?
Which method is used for taking input from the user?

Which method is used for taking input from the user?

Selecciona la respuesta correcta

What is the type of returned data from the <code>Console.ReadLine()</code> method?

What is the type of returned data from the Console.ReadLine() method?

Selecciona la respuesta correcta

What will be the output of the following statement?

What will be the output of the following statement?

Selecciona la respuesta correcta

Assuming that the user enters an empty string as an input, what will be the output of the following statement?

Assuming that the user enters an empty string as an input, what will be the output of the following statement?

Selecciona la respuesta correcta

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 1. Capítulo 3
some-alt