Full width home advertisement

Post Page Advertisement [Top]

Using statement 

Used to reference namespace. When class names are to be referred in the using directive, aliases for the classes can be used. using alias-name.

 namespace.class-name 

Namespace declaration 

  • Namespaces are a way of grouping types names and reducing the chance of name collisions and can contain both namespaces and other types. 
  • In C# you need to declare each class in a namespace. By default , namespace is automatically created with the same name as that of the project. CSharpArena is the namespace and MyClass class is contained in the namespace. 

Class declaration 

A C# source file can have several classes but only one class can have the Main method.

/*
* Created on June 16, 2018
* Sample C# Code
*/

using System;
using Alias = System.Console;
namespace CSharpArena
{
public class MyClass
{
/// <summary>
/// </summary>
/// <param name="args"></param>
public static void Main(string[] args )
{
// print a message
Alias.WriteLine("Welcome to C# Language");
}
}
}


Main() Function

The Main() Function is the entry point to your C# program it accepts a string array corresponding to the command line arguments passed. The Main function must be declared public and static else the compiler will not be able to identify the actual Main method.

No comments:

Post a Comment

Bottom Ad [Post Page]