Tuesday, 23 February 2016

C#.NET --- Sample Programs on Console Class

Sample programs in C#.NET

Lets us see one sample program which can utilize System.Console class

Console is class which contains input and output possible methods and it is in System namespace

Steps to write and execute a sample programs
Step 1 : open visual studio 2012
Step 2 :  goto file => new = > project
Step 3 : select C# language , select  .NET framework 4.5 and select “console applicatiom ” template .
Step 4 : Write project name as ConsoleDemo and click OK
Step  5  : Write the following code shown below 

using System; // importing section
namespace ConsoleDemo2  // namespace begining 
{
    class Program       // a class begining
    {
        static void Main(string[] args)  // method begining 
        {
            Console.Write("hi ,");
            Console.WriteLine("Mr. DOTNET ");
            Console.WriteLine("hello C#.NET");// prints output black screen
            Console.ReadKey();  // it awaits until we press any single screen
        }
    }
}

Step 6: Now build the project by going to BUILD menu select Build Solution and Click START
Step 7: If the code have no error . it will shows the output as below 

 Console class methods and properties

Methods :
  1. write() : It prints characters to the black screen 
  2. WriteLine() : It prints characters to the black screen and moves cursor to new line
  3. Read() : It reads a character from screen and written ASCII value of the char
  4. ReadLine() : It reads a string value and returns string
  5. ReadKey() : It reads a single character or it waits for taking single character
  6. Clear() : it wil clears black scree
  7. Beep() : it gives beep sound
Properties :
  1. backGroundColor
  2. foreGroundColor
  3. title
  4. windowSize
  5. cursorSize etc.,
If you want see remaining methods and properties while write Console. and press ctrl+space
the intelligence shows remaining methods and properties

1 comment:

  1. Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.

    c net training in electronic city

    ReplyDelete