In this c# tutorial, you will learn about the complete program structure of c# with examples.
C# Program Structure
- C# supports program structure with six sections. Out of six, the Main section is mandatory.
1. DOCUMENTATION SECTION
- It is an optional
- Gives the complete information about program like name of the program, author name, date, version and other details, etc
- C# supports two comment statements like java
2. PREDEFINED NAMESPACE SECTION
- It is an optional
- It is used to load the predefined .NET libraries using “using” keyword
- It is used to create different types of applications, algorithms, tools & OS, etc
- Ex. System, System.IO, System.Net, etc
Using Keyword
- It is a reserved keyword in C#.NET
- It is mainly used to load the system namespaces in .NET programming
- It is just like a java import statement.
3. USER DEFINED NAMESPACE SECTION
- It is also an optional section. Here we can create our own namespace
- Namespace is a set of classes / interfaces
- It is a container
- It is just like java packages.
Interfaces and Classes
4. INTERFACES
- It has only declaration, no body (no definition)
- All the methods in the interfaces are public by default
- All the variables in the interfaces are const by default
- Interfaces are defined using interface (reserved word)
- It has no constructor.
NOTE
- If the subclass inherits the interface, then the sub class must implement the methods of interface, else it is considered as an interface type.
5. CLASSES
- Collection of variables and methods are grouped together into a single entity (called class)
- Unlike java, c# class is internal by default
- All the variables, methods, properties in the classes are private by default
- Classes are defined using the reserved word class
- It supports constructors (parameter and parameterless).
6. MAIN() METHOD SECTION
- It is essential part in program
- It starts the program execution
- It is an important to note that, 1st letter of the Main() method in C# must be capitalized.
- Main() method can return only void and int types.
1. Main Returning Nothing
Example
2. Main Returning a Value
Example
More Tutorials
-
How to convert Word to Number in Bash Script
FacebookTweetPinLinkedInEmailShares0SharePrint In this bash tutorial, you will get convert word to number in bash script with examples.This is implemented using for loop, tr command, switch case in shell…
-
How to Count Word Frequency in Bash Script
FacebookTweetPinLinkedInEmailShares0SharePrint In this bash tutorial, you will get the program about how to count word frequency in bash script. This is done by using for loop,…
-
Bash Script – How to convert Number to Words
FacebookTweetPinLinkedInEmailShares0SharePrint In this tutorial, you will see how to convert numbers to words using bash script. This shell script can be done with the help of switch case…