Console Class And Its Members Is Static
This program describe that Console Class that is under System namespace is static class. We cannot create an instance of the static class. Methods of the Console Class is also static one. So It is not possible to call the methods of the Console class with its object, so always calls the static members with the class name instead of the object reference.
-------------------------------------------------------------------------------------------------------
using System;
class ConsoleClassTest
{
static void Main()
{
/* You never create an instance of Console class because Console class is a static class. */
Console c = new Console(); // This line generate an error.
/* You never call WriteLine method with Console class object. because first thing is that Console class is a static class and other is WriteLine() method is also static method so for calling static method we need to qualify it with class name instead of the object reference. */
c.WriteLine(); // This line also generate an error.
}
}
-------------------------------------------------------------------------------------------------------
So always call the method WriteLine() in the following manner.
Console.WriteLine("Happy To Program");
Console Class And Its Members Is Static
Reviewed by Baljeet Singh
on
06:43
Rating:
No comments: