Accepting and storing values in Member variables

So far we have seen different programming languages where they contain different libraries, different code snippets with different syntax, but other than these there is one thing common in all programming languages i.e input and output statements. In C#(a purely OOPs concept) we also use input and output statements with the following syntax.

example:

int Number;
Number=Convert.ToInt32(Console.ReadLine());

Here Console.ReadLine() is a function which accepts the inputs from user and store it in the variable 'Number'. 'Console.ReadLine() ' is a function of Console class and in turn the console class s said to be part of System namespace(collection of classes).

Convert.ToInt32() converts the data entered by the user to integer format. A user has a doubt that why an integer value is again converted into int by using those function, yes , while taking input a compiler generally takes input in string format so in order to convert the data entered by the user to prescribe type we use the function.
Convert() method Explicitly tells the compiler to convert one data type to another data type and this is called explicit conversion .The compiler performs an implicit conversion automatically. (exam: in implicit conversion converts the int data type to float or float datatype to int ,automatically).

0 Comments:

Post a Comment



Newer Post Older Post Home