C# First Program Syntax
C# is an Object-Oriented, Platform-Indepenedent High Level Programming Language used write the business logic in .Net Applications. To write a program in C# we need use this Basic Programming Syntax. This Article provides you the Basic Programming Syntax for Writing Program a C# Program.
C# First Program
C# is an Object-Oriented, Platform-Indepenedent High Level Programming Language used write the business logic in .Net Applications. To write a program in C# we need use this Basic Programming Syntax. This Article provides you the Basic Programming Syntax for Writing Program a C# Program.First C# Program
/* First C# Example */
using System; // Add the namespace to the Program
class Firstprg // Beginning of the Class
{
public static void Main()
{
Console.WriteLine("Welcome to the C# Training Session");
}
} // End of the classProgram Description
Comments
1. Used to provide Information about the Program.
2. Ignored by the Compiler.
3. Adding Comments is a Good Programming Practice
4. C# Supports Two Types of Comments
1./* */ - MultiLine Comment
2.// - SingleLine CommentAdding Namespace
using System;
1. using keyword is used to add the namespace in C#.
2. System - Namespace which contains predefined classes to perform basic Input-Output Operation.Class Definition
All the Programming Statements in a C# Program is placed in a class definition.
class Firstprg { }
1.class is a Keyword.
2.Firstprg is the class name.Main Method
public static void Main() { }
1. Main - Method name.
2. Starting point of the Program Execution.
3. public - Modifier which indicates that main method can be called from outside the class.
4. static - Modifier which indicates that main method is invoked before initializing the class by creating an Object.
5. void - Indicates that Method will return any value.C# Programming Statement
Console.WriteLine("Welcome to the C# Training Session");
1.Terminated by the Semicolon.
2.Console - Predefined class defined in the System namespace.
3.WriteLine - Method which displays the output.Steps to Create and Run the C# Program.
1. Install the .NetFramework in the System.
2. Type the C# program in the Text Editor like Notepad.
3. Save the file with Firstprm.cs Extension.
4. Open the .Net Command prompt and use csc command to compile the C# program.
csc Firstprm.cs
[Note: After the successful compilation an Firstprm.exe is created]
5. Type the Firstprm [exe file name] to execute the C# program.
6. Output will be displayed in the command prompt.
good for begineers..