C# Tutorial
We can avoid using prefix System to Console class by implementing the using System; statement.
Using alias option in C#, we can also avoid using prefix System.Console to use WriteLine method.
using alias-name = class-name;
In this C# program, alias is created for System.Console class and used alias name to access System.Console class methods.
/* This C# program Using alias for System namespace classes Also added single and multiline comments. */ using P = System.Console; // System is a namespace public class FirstApp { // Main method which starts the program execution. public static void Main() { // Prints welcome text P.WriteLine("Welcome to codingpointer.com to learn C#."); // Waits till any key press P.ReadKey(); } }
Output:
c:> csc FirstApp.cs c:> FirstApp Welcome to codingpointer.com to learn C#.
here declare string type text, also assiging string value and used in WriteLine method to display the string.
/* This C# program Using alias for System namespace classes Also added single and multiline comments. */ using P = System.Console; // System is a namespace public class FirstApp { // Main method which starts the program execution. public static void Main() { string text = "Welcome to codingpointer.com to learn C#."; // Prints welcome text P.WriteLine(text); // Waits till any key press P.ReadKey(); } }
Output:
c:> csc FirstApp.cs c:> FirstApp Welcome to codingpointer.com to learn C#.
Privacy Policy | Copyright2020 - All Rights Reserved. | Contact us | Report website issues in Github | Facebook page | Google+ page