C# Tutorial
Namespaces are the way to segregates the C# classes into reasonable groupings.
Let us consider C# statement,
System.Console.WriteLine("testing");
here System is the namespace in which Console class is located. class in the namespace can be accessed using dot (.) operator.
Using directive can be used to import the namespace System in the program. Once a namespace is imported, we can use the elements of that namespace without using the namespace as prefix.
This C# program using System namespace and not using System prefix for using methods of Console class.
using System; public class FirstApp { public static void Main() { Console.WriteLine("Welcome to codingpointer.com to learn C#."); Console.ReadKey(); } }
Output:
C:> csc FirstApp.cs C:> FirstApp Welcome to codingpointer.com to learn C#.
Comments play a very important role in the maintainance of any program.
Two types of comments in C#,
/* This C# program Using System namespace Also added single and multiline comments. */ using System; // System is a namespace public class FirstApp { // Main method which starts the program execution. public static void Main() { // Prints welcome text Console.WriteLine("Welcome to codingpointer.com to learn C#."); // Waits till any key press Console.ReadKey(); } }
Output:
C:> csc FirstApp.cs C:> FirstApp Welcome to codingpointer.com to learn C#.
namespace keyword is used to add class inside the namespace, here FirstApp class is added inside Test namespace.
/* This C# program Using System namespace Also added single and multiline comments. */ using System; // System is a namespace namespace Test { public class FirstApp { // Main method which starts the program execution. public static void Main() { // Prints welcome text Console.WriteLine("Welcome to codingpointer.com to learn C#."); // Waits till any key press Console.ReadKey(); } } }
Privacy Policy | Copyright2020 - All Rights Reserved. | Contact us | Report website issues in Github | Facebook page | Google+ page