|
C - Sharp(C#) Introduction |
C#, Pronounced "see-sharp." is a Microsoft .NET object-oriented programming language
which can be used to develop different types of .NET applications.C# will be familiar
to C and C++ programmers. C# is complete
object-oriented programming language that provides the following benefits |
- Type-Safety
- Garbage Collection
- Versioning
|
|
How to write and execute a simple C# Program |
Code snippet below shows a simple C# program. Let us understand the program structure line by line
- The using System; directive references a namespace called System that is provided by the Microsoft .NET Framework class library. This namespace contains the Console class that is used in the Main method. The using System; declaration tells the program that we are going to use the classes present in System namespace. We will discuss about namespaces in our later article.
- Next we create our class Hello
- In our Hello class we defined Main method. Main method indicates the starting point for running the program. When we run our program, the execution starts at the first line of the Main() method. The Main() method is marked
as static. We will discuss about static and Non static(also
called a Instance methods) in our later article.
- In our example, we are using "Console" class which is part of .NET framework class
library. C# language does not itself provide a class library. All .NET supported
languages Visual C#,Visual Basic.NET and Visual C++.NET use the classes from .NET
framework class library.
|
|
using
System; //Namespace
Declaration
class
Hello
//Class Declaration
{
public
static void Main()
// Main method
{
Console.WriteLine("Hello from PRAGIM Technologies");
//Prints message to the console
}
}
|
|
|
Instructions to execute a console application |
The above program execution depends on how we have written it.
- If we have written the program in Visual Studio, pressing ctrl+F5 together will run the application.
- If we have written the program in a notepad, then follow the following instructions
-
Change the notepad extension, from .txt to .cs. All C# source code files have .cs extension.
-
Go to visual studio command prompt by selecting Start -> All Programs -> Microsoft Visual Studio 2005 -> Visual Studio Tools -> Visual Studio 2005 Command Prompt
-
In the command prompt window, navigate to the path where we have saved the .cs file.
-
Enter the below command. CSC stands for CSharp Compiler.
CSC FileName.CS
-
This would generate FileName.exe file in the same directory where we have our FileName.cs
-
To run the executable, enter FileName.exe in the command prompt and press enter key.
|
|
|
Other related articles :
|
Njoy Programming
ByPrasad Cherukuri
|