This is a simple C# program. Call this program Example.cs.

using System; class MainClass { public static void Main() { Console.WriteLine("A simple C# program."); } }

Using csc.exe, the C# Command-Line Compiler

To create and run programs using the C# command-line compiler: 1. Enter the program using a text editor. 2. Compile the program. 3. Run the program. Compiling the Program
C:\>csc Example.cs

Prior to running csc.exe, you may need to run the batch file vcvars32.bat, which is typically found in the //Program Files/Microsoft Visual Studio.NET/Vc7/Bin directory. 1. The name of a C# program is arbitrary 2. By convention, C# programs use the .cs file extension
The C# Keywords
abstract Byte class delegate event fixed if internal new override readonly short struct try as case const do explicit float implicit is null params ref sizeof switch typeof base catch continue double extern for in lock object private return stackalloc this uint bool char decimal else false foreach int long operator protected sbyte static throw ulong break checked default enum finally goto interface namespace out public sealed string true unchecked

unsafe void ushort while using virtual volatile C# has the following reserved keywords: abstract break byte checked class default delegate enum event finally fixed goto if Interface Internal namespace new out override public readonly sealed short string struct true try unchecked unsafe void volatile while ushort using virtual typeof uint ulong switch this throw params ref private protected sbyte Is lock object long operator Implicit In Int float for foreach do explicit double extern else const continue decimal as base bool case catch char false null return stackalloc sizeof static .

Windows.DLL WinEvents .DLL /r:System. reference types. value types 2.cs C#'s Value Types C# contains two general categories of built-in data types: 1. the .Drawing.Forms. The C# Value Types Type Meaning bool Represents true/false values byte 8-bit unsigned integer char Character decimal Numeric type for financial calculations double Double-precision floating point float Single-precision floating point int Integer long Long integer sbyte 8-bit signed integer short Short integer uint An unsigned integer ulong An unsigned long integer ushort An unsigned short integer Converting Numeric Strings to Their Internal Representation For the numeric types.DLL /r:System.Compile csharp source code in command line csc /r:System.NET Structure Name C# Name Decimal decimal Double double Single float . C#'s reference types are defined by classes.NET structure names and their C# keyword equivalents are shown here: .

Byte 0 to 255 16 /u0000 to /uffff Boolean 8Primitive Description byte bit integer char System. Thus. long integer. with 28 to 29 digits of precision double bit floating point System. 9. 100 is an int. For example. 6. 5.Boolean true or false System.95M is a decimal literal. For example. A hexadecimal literal must begin with 0x (a zero followed by an x). For example.9 10^28. 2. Primitives in C# Type Range bool System. 1. Literals literals refer to fixed values that are represented in their human-readable form. append a u or U.0 10^-28 to (+/)7.Int16 Int32 Int64 UInt16 UInt32 UInt64 Byte Sbyte short int long ushort uint ulong byte sbyte 1. The structures are defined inside the System namespace. use ul or UL. To specify an unsigned integer value. The fully qualified name for Int32 is System. but 12L is a long. 7. append an l or an L. To specify a float literal. follow its value with an m or M. To specify a decimal literal. append an F or f to the constant. 4. To specify an unsigned.19F is of type float. 10. 12 is an int.Char bit Unicode character decimal System. For example. 2.Int32.Double 64- . but 100U is a uint. 3. 984375UL is of type ulong.Decimal 128bit decimal (+/-)1. To specify a long literal.

UInt32 Unsigned 32-bit number uint .Int16 8-128 to 127 16-32.147.807 sbyte bit integer short bit integer string System.854.647 No 0 to 4.295 640 to 18.4 10^38. with 7 digits of precision int System.483.036.615 160 to 65.854.UInt64 bit unsigned integer ushort System.551.775.UInt32 bit unsigned integer ulong System.036.967.UInt16 Unsigned 16-bit number System.147.79769313486232e308 float System.073.483.648 to 2.Byte Unsigned 8-bit number System.744.String not applicable String is an immutable variable length string.294.967.483.775.768 to 32.223.Single bit floating point (+/-)1.Int16 Signed 16-bit number System.535 uint System.SByte System.UInt16 bit unsigned integer System Types and C# Shorthand C# Shorthand Range sbyte 128 to 127 byte 0 to 255 short 32.709.Int32 bit unsigned integer 3210^-45 to (+/- 32-2.295 No Yes Yes CLS Compliant? No System Type Meaning in Life System.SByte Signed 8-bit number System.372.79769313486232e308 to 1.446.Int32 Signed 32-bit number System.767 System.223.483.372.535 int Yes 2.808 to 9.648 to 2.294.647 long System.1. 320 to 4.Int64 64bit integer ushort 0 to 65.5 )3.768 to 32.

Int64 9.String Represents a set of Unico System.854.223.Double 64System.807 Signed 64-bit number No 0 to 18.Single 32System.551.615 Yes System.372.223.709.372.long Yes System.744.UInt64 Unsigned 64-bit number System.5 * 10^-45 to 3.NET universe .4 * 10^38 bit floating point number float Yes 5.Object The base Yes Any type can be stored in an object variable class of all types in the .036.0 * 10^-324 to 1.073.Char A single 16System.446.775.775.808 to 9.854.7 * 10^308 bit floating point number double bool true or false ty decimal 10^0 to 10^28 string Yes Limited by system memory de characters object Yes Yes System.Decimal A 96-bit signed number System.Boolean Represents truth or falsi ulong char U0000 to Uffff bit Unicode character Yes 1.036.

Sign up to vote on this title
UsefulNot useful