1 / 4
2 / 4
3 / 4
4 / 4

Thursday 6 February 2020

What is "System.Console.WriteLine" in C# console program?




System:-

It is a namespace. As you know namespace is a logical container of types i.e. Class, Interface, Delegate, Enumeration, Structures, etc.

Console:-

It is a static class under the Framework Class Library of our language which provides a set of members through which we can perform I/O operations.
we can not inherit the console class .so to call the members of this class we need to prefix the class name.


WriteLine:-

WriteLine is a method of class Console. It will display the current output on the monitor with a line break/terminator.
All the members of the console class are static.
WriteLine method have 19 overloads in this class.


So, we write like this:-

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            System.Console.WriteLine();
        }
    }
}

(or) we can import the System namespace above our code like this

using System; //importing namespace
namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine();
        }
    }
}

>>In System namespace 

namespace System
{
    public static class Console
    {
        ..........................
        ..........................
        public static void WriteLine(); 
        ..........................
        ..........................
     }
}

No comments:

Post a Comment

If you have any doubts please let me know