Let's create your first C# program.
class Program
{
static void Main(string[] args)
{
int i = 0;
int j = 2;
System.Console.WriteLine("i=" + i);
System.Console.WriteLine("j=" + j);
}
}
The output:
i=0
j=2
The code above defines two variables and output their values.
C# source files typically have the file extension .cs
.
Save the code to Program.cs
file and issue the csc
command to compile it.
C:\g>csc Program.cs
Microsoft (R) Visual C# 2010 Compiler version 4.0.30319.1
Copyright (C) Microsoft Corporation. All rights reserved.
Check the output of the compiling:
C:\g>dir Program.exe
Volume in drive C has no label.
Volume Serial Number is 4047-6D6A
Directory of C:\g
11/27/2010 11:04 AM 3,584 Program.exe
1 File(s) 3,584 bytes
0 Dir(s) 14,309,142,528 bytes free
C:\g>
Execute the Programm.exe
.
C:\g>Program.exe
i=0
j=2
The C# compiler compiles the source code to assembly.
.net framework uses the assembly
to package and deploy.
An assembly can be either an application(.exe
file) or a library(.dll
file).
java2s.com | Contact Us | Privacy Policy |
Copyright 2009 - 12 Demo Source and Support. All rights reserved. |
All other trademarks are property of their respective owners. |