Working With Console Class


  • Console is a class used to work with Input and Output streams
  • Console class is present in system Namespace

Methods / Functions with Console class


  1. Write(“Message”)
  2. WriteLine(“Message”)
  3. Read( )
  4. ReadLine( )
  5. Clear( ) 
 1.Write(“Message”)
  • This method is used to display any message to the user in the output stream
  • After displaying the message blinking cursor remains in the same line
  • Ex: Console.Write(“Welcome”);
  • O / p: Welcome_
2.WriteLine(“Message”)
  • This method is used to display required message to the user on the output stream
  • After displaying the message blinking cursor moves to a new line
  • Ex: Console.WriteLine(“Welcome”)
  • O / p: Welcome
3.Read()
  • This method is used to read a single character from the input stream

4.ReadLine()
  • This method is used to read a group of character from the input stream
5.Clear()
  • This method is used to delete the contents of screen and same as clrscr( ) in c / c++
Reading the Data from the User
  • To Read the data from the user there are 2 methods available
         1)    ReadLine( )
        2)    Read( )


Differences between Read and ReadLine


SNO
           Read(  )
            ReadLine(  )
01
Reads Single / Next Character from the Input Stream
Reads Group of Characters from the Input  Stream
02
Reads Maximum of only 1 character
Reads Maximum of 255 characters (Limit of OS Command prompt)
03
Reads ASCII value of the integer
Reads string value of the Character(s)
04
Return Type is int / integer
Return Type is string


No comments:

Post a Comment