Вы находитесь на странице: 1из 12

C# PROGRAMMING WITH .NET3.

By Miss S.V.Koparde

Building C# Applications Using csc.exe


Open Notepad and enter the following:

using System; class TestApp { public static void Main () { Console.WriteLine ("Testing! 1, 2, 3"); } } Save the file in a convenient location (e.g., C:\CscExample) as TestApp.cs

By Miss S.V.Koparde

The different options of c# compiler


1)/out

This option is used to specify the name of the assembly to be created

By default, the assembly name is the same as the name of the initial input *.cs file (in the case of a *.dll) or the name of the type containing the programs Main() method (in the case of an *.exe)
csc /out:My.exe File.cs

2) /target:exe This option builds an executable console application This is the default file output type, and thus may be omitted when building this application type

By Miss S.V.Koparde

3) /target:library This option builds a single-file *.dll assembly csc /target:library File.cs

4) /target:module This option builds a module Modules are elements of multifile assemblies 5)/target:winexe

Although you are free to build Windows-based applications using the /target:exe flag, the /target:winexe flag prevents a console window from appearing in the background
By Miss S.V.Koparde

Referencing External Assemblies


using System; using System.Windows.Forms; class TestApp { public static void Main() { Console.WriteLine("Testing! 1, 2, 3"); MessageBox.Show("Hello..."); } }
By Miss S.V.Koparde

Compiling Multiple Source Files using System; using System.Windows.Forms; class HelloMessage { public void Speak() { MessageBox.Show("Hello..."); } }
By Miss S.V.Koparde

Consider the following TestApp class which uses HelloMessage class:


using System; class TestApp { public static void Main () { Console.WriteLine("Testing! 1, 2, 3"); HelloMessage h = new HelloMessage(); h.Speak(); } } csc /r:System.Windows.Forms.dll testapp.cs hellomsg.cs csc /r:System.Windows.Forms.dll *.cs

By Miss S.V.Koparde

C# Language Fundamentals
C# demands that all program logic is contained within a type definition (class, interface, structure,enumeration, delegate The Anatomy of a Simple C# Program: //C# files end with a *.cs file extension. using System; class HelloClass { public static int Main(string[] args) { Console.WriteLine("Hello world"); return 0; } }
By Miss S.V.Koparde

Variations on the Main ( ) Method


//Integer return type, array of strings as argument. public static int Main(string[] args) { // Process command line arguments. // Make some objects. //Return a value to the system. }------------------------------------------------------------------// No return type, no arguments. public static void Main() { // Make some objects. }----------------------------------------------------------------// Integer return type, no arguments. public static int Main() { // Make some objects. // Return a value to the system. }
By Miss S.V.Koparde

Processing Command Line Parameters


using System; classHelloClass { public static int Main(string[] args) { Console.WriteLine("***** Command line args *****"); for(int x = 0; x <args.Length; x++) Console.WriteLine("Arg: {0} ", args[x]); Console.WriteLine("Hello World!"); return 0; } }
By Miss S.V.Koparde

Alternative to the standard for loop C# "foreach" keyword. // Notice we have no need to check the size of the array when using //'foreach'. public static int Main(string[] args) { foreach(string s in args) Console.WriteLine("Arg: {0} ", s); ... }
By Miss S.V.Koparde

The System.Environment Class


using System; class Exp { public static void Main() { // OS running this app? Console.WriteLine("Current OS: {0} ", Environment.OSVersion); // Directory containing this app? Console.WriteLine("Current Directory: {0}",Environment.CurrentDirectory); // List the drives on this machine. string[] drives = Environment.GetLogicalDrives(); for (int i = 0; i < drives.Length; i++) Console.WriteLine("Drive {0} : {1} ", i, drives[i]); // Which version of the .NET platform is running this app? Console.WriteLine("Executing version of .NET: {0} ",Environment.Version); } } By Miss S.V.Koparde

Вам также может понравиться