Friday, August 13, 2010

Read & Write operations using Console class

Console Class:


In this class we use two important methods named WriteLine() and ReadLine(). This class contained in the System namespace.

Eg: Print a message

class WriteString
{
public static void Main()
{
   System.Console.WriteLine("Welcome to C#.")
}
}

Eg: read a string

using System;
class WriteString
{
public static void Main()
{
   Console.WriteLine("Enter a string ");
   string str = Console.ReadLine();
   Console.WriteLine("You entered = " + str);
}
}

WriteLine() pumps a text string to the output stream. ReadLine() allows you to receive information from the input stream. The ReadLine(0 method returns a string value.

No comments: