"Web Service Programming - Develop Network Services with C # .NET" - Beijing Hope Publishing House
Chapter II C # Basic Law
2.1 How to Compile C # Language 2.1.1 Intermediate Language 2.1.2 Compiling Parameters
Csc.exe has a lot of switch options when compiling C # program code into IL files
@ CSC @ r @ rp1.rsp @ csc @ r 的 的 内容 内容 / target: exe /out:sample.exe sample.cs @ Used to specify a response file, a response file is a file containing a number of RSP suffixes that compile options, In the beginning #, annotation can specify multiple responses such as: csc @ rsp1.rsp @ rp2.rsp /?, / Help / addModule Add module to file CSC /ADDModule :Module1.dll;Module2.dll my.cs / baseaddress specifies that when compiled into a DLL file, the DLL loaded the address csc / baseaddress: 0x1111000 / target: library my.cs can be a decimal, octal, hexadecimal / bugreport, put errors in a file such as: CSC / BugReport: bugs.txt my.cs / check / codepage / debug This option creates a .pdb file such as: CSC / Dubug my.cs / define can be used to define the compilation variables that are not defined in the original file such as CSC / Define: Fine my.cs
/ DOC will compile the comments in the original code into an XML file CSC /DOC: My.xml my.csource / main designation of the port of Main, such as: csc my1.cs my3.cs / main: MY1 / NOLOGO / Nooutput does not output any file, but you can see compilation information such as: csc / nooutput my.cs / nostdlib / noout / optMize / out specify output files such as: csc /out :h.exe Hee.cs / recurse CSC / Target : library /out:dir2.dll /recurse: dir1/dir2/.cs / reference csc /r :system.dll;myexec.exe;myblib.dll my.cs Add DLL / Target ● / Target: EXE CSC / Target : exe my.cs ● / Target: library csc / target: library my.cs ● / target: Winexe CSC / Target: Winexe my.cs ● / target: module csc / target: module my.cs resource is the opposite of the LinkResource function, He is embedded in the output file in the output file / unsafe csc / unsafe my.cs / warn csc / warn: 0 my.cs 0: Close warning 1: Only a serious warning 2: Level 1 and not serious 3 : Level 2 and not serious 4: Level 3 and unscrupulous / warnaserror CSC / Warnaserror Myj.cs Warning When Error / Win32In CSC /WIN32ICON: IMYICON.ICO MyCs Insert Icon File / Win32Res Insert a Win32 Resource CSC /WIN32RES :WINRF.RES MT.CS2.2 in the output file Value type
C # Value Types 3 ● Simple Types ● Structural Types (ENUMERATION TYPES 2.2.1
Simple Types is divided into Boolean and numerical types, C #'s Boolean and numerical types are strictly distinguished, Boolean only TRUE and FALSE values, cannot be divided into: Integer (Sbyte) , Byte, Short, USHORT, INT, UINT, Long, Ulong, Char, Float, Double, Decimal, 2.2.2 Structure Type (Struck Types)
As follows: ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- UINT NO;}}.
---------------------
Can be accessed as follows: student1.address.city = "beijing";
2.2.3 Enumeration Type (Enumeration Types) ENUM Color {Red, Blue, Green, White, Black};
According to the system default: the first one is 0 sequentially, can also be set according to yourself
2.3 Reference Type
C # has the following reference type ● Object type ● Class Type ● Interface ● Representative Yuan ● String Type ● Array 2.3.1 Object Type
Such as: Object etcobject = 1243;
2.3.2 Class Type A class type contains data members, function members, nested types, and data members are constants, static fields, and events. Functions members include methods, attributes, indexing, operation floating, constructor, and destructors. C # only allows for inheritance, but can derive from multiple interfaces
2.3.3 interface
2.3.4 Delegate is as follows: -------------------------------------------------------------------------------------------------------------------- "Declaration a representative public class theclass {Public int instanceMethod () {Console.Write ("call the instance method"); return 0;} static public int statness () {console.write ("call the static method"); return 0;}} public class test {static public void main () {THECLASS P = New THECLASS (); // Point to non-static method instancethod thedelegate d = new thedelegate (p.instanceth); // call non-static method D (); // Representative Pointing Static Method StaticMethod D = New Tedlegate (THECLASS.STATITICMETHOD); // Call Static Method D ();}} -------------------- 2.3 .5 String Type 2.3.6 Array String [] etcstr = {"a", "b", "c"}; = etcstr [0] = "a"; etcstr [1] = "b"; etc 4tr [2 ] = "C";
INT [,] arr = {{0, 1}, {2, 3}, {4, 5}} = arr [0,0] = 0; Arr [0, 1] = 1; Arr [1,0] = 2; Arr [1, 1] = 3; Arr [2,0] = 4; Arr [2, 2] = 5;
INT nVAR = 5; int [] arrtoo = new int [nvar];
2.4 Packing and Box 2.2.1 Packing Packing is the implicit conversion of value types (Object) int number = 10; in the stack Object objNumber = Number; in the heap
Number and objNumber after packing!
2.4.2 Folding box converts an object to a value type! INT NOTOBJECTNUMBER = (int) objNumber;
2.5 Constants and Variables 2.5.1 Variables and C / C are different to @ 来 明 一 关 一 关 也 一!! C # has no global variable!
2.5.2 Constant can be then a value type and reference type!
2.6 Process Control 2.6.1 Conditions Statement 1. IF statement 2. Switch statement is in C #, if you don't touch BREAK, C # will automatically traverse the next case from a CASE, if there is no Break or Goto, the compiler will report an error! And different from C / C is that Switch supports strings for expressions. C # Switch statement can be a String type!
2.6.2 Cyclic statement C # introduces Foreach in VB as follows: ----------------------- Using System; Using System.Collections Download Adobe Reader: ----------------------------------------- USING SYSTEM; USING SYSTEM.COLLECTIONS;
A summary description of Namespace UseForeAach {///
2.6.3 conditional compilation pretreatment methods and properties of a pretreatment conditions -------------------------- using System; public class SquareSample {public void Calesquare (int nsquence) {nsquared = nsideLength * nsideLength;} public int calcsquare (int nsideLength) {return nsideLength * nsideLength;}}
class SquareApp {public static void Main () {SquareSample sq = new SquareSample (); int nSquared = 0; #if CALC_W_OUT_PARAM sq.CalcSquare (20.out nSquared); #else nSquared = sq.CalcSquare (15); #endif Console .Writeline (nsquared.tostring ());}} // Since the CALC_W_OUT_PARAM is not defined, use the following command // csc / define.cs: CALC_W_OUT_PARAM Define.cs ------------ ----------------
------------------------------
! #Define DEBUG # define RELEASE # define DEMOVERSION # if DEMOVERSION && DEBUG # warning You are Building a demo version # endif # if DEBUG && DEMOVERSION # error You can not build a debug demoversion # endifusing System; class Demo {public static void Main ( ) {Console.write ("demo Application");}} --------------------------------
-------------------------------------
// # define DEBUG # define RELEASE # define DEMOVERSION # if DEBUG # undef DEMOVERSION # endifusing System; class Demo {public static void Main () {#if DEBUG Console.WriteLine ( "Debug version"); # elif RELEASE && DEMOVERSINO! Console.writeline ("full release version"); # Else Console.writeline ("Demo Version"); # Endif}} (I don't know the results) ---------------- ------------------
The above is the code for several pre-processing methods.
2. Conditional properties ---------------------------------- # Define debugusing system; class info {[conditional DEBUG ")] public static void Trace (string strMessage) {Console.WriteLine (strMessage);} [conditional (" DEBUG ")] public static void TraceX (string strFormat, params object & #; list) {Console.WriteLine (stringFormat, List);}} Class TestConditional {public static void main () {info.tric ("Cool"); info.triccex ("{0 {{1} {2}", "c", "u", 2001) }}
// wrong? --------------------------------