C# Programming: Input and Data Type Conversion with Console, Schemes and Mind Maps of English

An example of a simple c# program that uses the console to take user input and convert data types. The main method is explained, as well as the use of integer and float data types and the parse method for string to data type conversion.

Typology: Schemes and Mind Maps

2020/2021

Uploaded on 11/08/2021

ljculalic
ljculalic 🇵🇭

1 document

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
// The namespaces are used to organize classes in a project. The namespace
declaration is a collection of classes. In my case, the namespace is DataTypesApp
contains the class DataTypesProgram.
// The using keyword is used to access the classes available in a namespace.
using System;
namespace DataTypesApp
{
class DataTypesProgram
{
static void Main(string[] args)
// It is a keyword and used to specify the main method
Every C# application contains one (1) Main method. The Main method is the
starting point of every application, and it contains the statements that will be
executed.
In the sample program, we use the;
int apple;
// Integer - is a data type used to represent real numbers that do not have
fractional values
float price;
// a data type composed of a number that is not an integer
// so here we are using again the Console.WriteLine Method
Console.Write("Enter the pieces of apple: "); // it Writes the text representation,
this is where we input the number of apples
apple = int.Parse(Console.ReadLine());// this part is when it used to read the
next line of characters from the standard input
and again you can see the Parse where in // parsing is the process where a string
of commands – usually a program – is separated into more easily processed
components, which are analyzed for correct syntax and then attached to tags that
define each component.
Console.Write("Enter the total price of " + apple + " apple(s): ");
price = float.Parse(Console.ReadLine()); // float. Parse method uses
your current culture settings by default
int newVariable = (int)price;
Console.WriteLine("The total price of " + apple + " apple(s) is " + price);
// Console.WriteLine() is a method that works with Console applications. It
prints the string argument to the console screen
Console.WriteLine("The value of original price is " + price);
Console.WriteLine("The value of converted price is " + (int)price);
Console.WriteLine("Press any key to exit......");
Console.ReadKey();
pf2

Partial preview of the text

Download C# Programming: Input and Data Type Conversion with Console and more Schemes and Mind Maps English in PDF only on Docsity!

// The namespaces are used to organize classes in a project. The namespace declaration is a collection of classes. In my case, the namespace is DataTypesApp contains the class DataTypesProgram. // The using keyword is used to access the classes available in a namespace. using System; namespace DataTypesApp { class DataTypesProgram { static void Main(string[] args) // It is a keyword and used to specify the main method Every C# application contains one (1) Main method. The Main method is the starting point of every application, and it contains the statements that will be executed. In the sample program, we use the; int apple; // Integer - is a data type used to represent real numbers that do not have fractional values float price; // a data type composed of a number that is not an integer

// so here we are using again the Console.WriteLine Method

Console.Write("Enter the pieces of apple: "); // it Writes the text representation,

this is where we input the number of apples apple = int.Parse(Console.ReadLine());// this part is when it used to read the next line of characters from the standard input and again you can see the Parse where in // parsing is the process where a string of commands – usually a program – is separated into more easily processed components, which are analyzed for correct syntax and then attached to tags that define each component. Console.Write("Enter the total price of " + apple + " apple(s): "); price = float.Parse(Console.ReadLine()); // float. Parse method uses your current culture settings by default int newVariable = (int)price; Console.WriteLine("The total price of " + apple + " apple(s) is " + price); // Console.WriteLine() is a method that works with Console applications. It prints the string argument to the console screen Console.WriteLine("The value of original price is " + price); Console.WriteLine("The value of converted price is " + (int)price); Console.WriteLine("Press any key to exit......"); Console.ReadKey();