.NET FrameworkNET Framework http://www.NET Frameworknakov.NET Frameworkcom/dotnet/ C# academy.NET Frameworkdevbg.NET Frameworkorg C
C++ C# Java Pascal/Delphi Perl Python .NET FrameworkNET Framework (1) C# C# C#
(expressions) (statements) (2) , , XML C#
- C++, Java Delphi : C/C++ Java Java C++ ( ) Delphi (, , ) :
XML C# Anders Hejlsberg, Delphi -o , , XML- header , IDL ,
5.ToString() C#
(code access security role-based security) ECMA ISO C# ,
Main() , (namespaces) namespace C# HelloCSharp.cs using System; class HelloCSharp { static void Main() { Console.WriteLine("Hello, C#"); } } Java
C++ ? using System; class static void Main()
#include C++ import Java uses Delphi , System.Console #1 csc HelloCSharp.cs HelloCSharp.exe
Hello, C# #2 , Visual Studio.NET FrameworkNET [Ctrl+F5] C# abstract as base bool break byte case
catch char checked class const continue decimal default delegate do double else enum
event explicit extern false finally fixed float for foreach goto if implici t in
int interfac e interna l is lock long namespace new null object operato r
out override params private protecte d public readonl y ref return sbyte sealed short
sizeof stackallo c static string struct switch this throw true try C#
(value types) (reference types) - () garbage collector- o
(, built-in) C# (value types) int i; enum State { Off, On } struct Point { int x, y; } (reference types)
class Foo: Bar, IFoo {...} interface IFoo: IBar {...} string[] a = new string[5]; delegate void Empty(); C# CTS .NET FrameworkNET Framework int = System.Int32 C# (built-in data types)
C C++ byte, sbyte, int, uint, long, ulong float, double, decimal char Unicode bool (true false) string Unicode object
(implicit conversion) , : int long, float double, long float, byte short (explicit conversion) - long int, double float, char short, int char, sbyte uint
checked System.OverflowException byte b8 = 255; short sh16 = b8; // implicit conversion int i32 = sh16; // implicit conversion float f = i32; // implicit - possible loss of precision! double d = f; // implicit conversion checked { byte byte8 = (byte) sh16; // explicit conversion // OverflowException is possible! ushort ush16 = (ushort) sh16; // explicit conversion // OverflowException is possible if sh16 is negative! } unchecked { uint ui32 = 1234567890; sbyte sb8 = (sbyte) ui32; // explicit conversion // OverflowException is not thrown in unchecked mode } (enumerations)
C# enum.NET Framework : enum Days {Sat, Sun, Mon, Tue, Wed, Thu, Fri}; int, int (enumerations) System.Enum
[Flags] [Flags] public enum FileAccess { Read = 1, Write = 2, Execute = 4, ReadWrite = Read | Write } //... Console.WriteLine( FileAccess.ReadWrite | FileAccess.Execute); // The result is: "ReadWrite, Execute" , Unicode
int _ = 118; bool \u1027\u11af = true; Microsoft PascalCase , namespace-, , , , , camelCase C# ( C++, Java Delphi):
( ) - int count; public static int mCounter; compile-time const runtime readonly
C# : Compile-time : public const double PI = 3.1415926535897932; const string COMPANY_NAME = " "; " ";; const
C# : Run-time public readonly DateTime NOW = DateTime.Now; readonly , ( )
C++ Java, : +, -, *, /, %, ++, -: &&, ||, !, ^, true, false : &, |, ^, ~, <<, >> : + : ==, !=, <, >, <=, >= : =, +=, -=, *=, /=, %=, &=, |=, ^=, <<=, >>= : as, is, sizeof, typeof : ., [], (), ?:, new, checked, unchecked, unsafe (expressions) ,
expressions C++ Java : a = b = c = 20; // 20 (+5)*(32-a)%b // " ";" "; + " ";" "; // (stringstring) Math.Cos(Math.PI/x) // typeof(obj) // System.Type (int) arr[idx1][idx2] // int new Student() // Student (currentValue <= MAX_VALUE) // (statements) (statements) C++ Java : { }
(.NET Framework lock) (statements) - .NET Framework : sum = (a+b)/2; // (string<> = <>) PrintReport(report); // student = new Student(" ";
" ";, 3, 42688); // { } , .NET Framework : Report report = GenerateReport(period); report.Print(); (conditional statements) if if-else
if (orderItem.Ammount > ammountInStock) { MessageBox.Show(" ";Not in stock!" ";, " ";error" ";); } if (Valid(order)) { ProcessOrder(order); } else { MessageBox.Show(" ";Invalid order!" ";, " ";error" ";); } (conditional statements) switch case string enum switch (characterCase) {
case CharacterCasing.Lower: text = text.ToLower(); break; case CharacterCasing.Upper: text = text.ToUpper(); break; default: MessageBox.Show(" ";Invalid case!" ";, " ";error" ";); ); break; } (iteration statements) for- // 1 100 for (int i=1; i<=100; i++) { int i2 = i*i; Console.WriteLine(i + " "; * " "; + i + " "; = " "; + i2); }
while- // result = a^b result = 1; while (b > 0) { result = result * a; b--; } (iteration statements) do-while // do { ch = ReadNextCharacter(stream); }
while (ch != '\n'); foreach string[] names = GetNames(); // foreach (string name in names) { Console.WriteLine(name); } break, continue goto return // target a[]
int position = -1; for (int i=0; i
try-finally try-catch-finally lock checked, unchecked fixed #3 , 25 Digits.cs using System; public class Digits { static void Main()
{ for (int d1=1; d1<=9; d1++) for (int d2=0; d2<=9; d2++) { int d3 = 25 - d1 - d2; if ((d3 >= 0) && (d3 <= 9)) { int n = d1*100 + d2*10 + d3; Console.WriteLine(n); } } } } #4 VS.NET FrameworkNET #5 ILDASM ILDASM Digits.exe
Order orders[]; // /* , . , Deleted */ foreach (Order order in customer.rders) { if (!AllItemsInStock(order)) { order.Status = OrderStatus.Deleted; } } XML
, /// XML JavaDoc Java , C# XML XML - XML /// /// /// ///
The main entry point for the application.
The command line arguments static void Main(string[] args) { // ... } /// /// /// /// /// ///
Calculates the square of a number
The number to calculate
The calculated square Thrown when the result is too big to be stored in an int public static int square(int num) { // ...
} XML
, , .. Visual Studio IntelliSense , , .. Visual Studio Object Browser , , (property)) #6 XML C#
csc MainClass.cs /doc:MainClassComments.xml HTML Visual Studio .NET FrameworkNET #region, #endregion , "" Visual Studio #if, #else, #elif, #endif ()
#define, #undef #warning, #error BCL Console.ReadLine() string Console.Read() char
Console.Write() ( string, int, float, double, ) Console.WriteLine(" "; {0:dd.MM.yyyy} ." ";, DateTime.Now); Console.WriteLine() Conlsole.Write(), int a = Int32.Parse(Console.ReadLine()); int b = Int32.Parse(Console.ReadLine()); Console.WriteLine(" ";{0} + {1} = {2}" ";, a, b, a+b); // (string 3 2 ) // 2 + 3 = 5 Console.WriteLine( " "; {0:dd.MM.yyyy} ." ";, DateTime.Now); // 13.05.2004 .
Console.WriteLine(" ";: {0,12:C}" ";, 27); // : 27,00 // (string ) String name = " ";" ";; Console.WriteLine(" ";, {0}, {1:HH:mm}!" ";, name, DateTime.Now); // , , 16:43! #7 .NET FrameworkNET Framework 1.NET Framework Console.WriteLine() ( F1 Visual Studio .NET FrameworkNET) 2.NET Framework "composite formatting" MSDN C# ?
1.NET Framework C#, 2.NET Framework 3.NET Framework 4.NET Framework 5.NET Framework ", <>!".NET Framework C#, .NET Framework , , 5 .NET Framework 3 debugger- Visual Studio .NET FrameworkNET.NET Framework 3, , .NET Framework ? XML
5 HTML Visual Studio .NET FrameworkNET.NET Framework 7.NET Framework , .NET Framework ( ) .NET Framework 10- , , 2 ( ).NET Framework 8.NET Framework , , , "+" "-" .NET Framework 6.NET Framework MSDN Training, Programming C# (MOC 2124C), Module 2: Overview of C# MSDN Training, Programming C# (MOC 2124C), Module 3: Using Value-Type Variables
Jessy Liberty, Programming C#, Second Edition, OReilly, 2002, ISBN 0-596-00309-9 Svetlin Nakov, .NET FrameworkNET Framework Overview http://www.NET Frameworknakov.NET Frameworkcom/publications/Nakov-DotNET-Frame work-Overview-english.NET Frameworkppt MSDN, C# Keywords http://msdn.NET Frameworkmicrosoft.NET Frameworkcom/library/en-us/csref/html/vclrfcs harpkeywords_pg.NET Frameworkasp MSDN, C# Built-in Types Table http://msdn.NET Frameworkmicrosoft.NET Frameworkcom/library/en-us/csref/html/vclrfb uiltintypes.NET Frameworkasp MSDN, Common Type System Overview http://msdn.NET Frameworkmicrosoft.NET Frameworkcom/library/en-us/cpguide/html/cpc oncommontypesystemoverview.NET Frameworkasp
MSDN, Enumerations http://msdn.NET Frameworkmicrosoft.NET Frameworkcom/library/en-us/cpguide/html/cpc onEnumerations.NET Frameworkasp MSDN, C# Operators http://msdn.NET Frameworkmicrosoft.NET Frameworkcom/library/en-us/csref/html/vclrfC SharpOperators.NET Frameworkasp MSDN, Statements (C# Programmer's Reference) http://msdn.NET Frameworkmicrosoft.NET Frameworkcom/library/en-us/csref/html/vclrfst atements.NET Frameworkasp MSDN, XML Documentation Tutorial (C# Programmer's Reference) http ://msdn.NET Frameworkmicrosoft.NET Frameworkcom/library/en-us/csref/html/vcwlkxmld ocumentationtutorial.NET Frameworkasp
MSDN, C# Preprocessor Directives - http://msdn.NET Frameworkmicrosoft.NET Frameworkcom/library/en-us/csref/html/vclrfPr eprocessorDirectives.NET Frameworkasp MSDN, Composite Formatting http://msdn.NET Frameworkmicrosoft.NET Frameworkcom/library/en-us/cpguide/html/cpc oncompositeformatting.NET Frameworkasp MSDN, Console Class (.NET FrameworkNET Framework) http://msdn.NET Frameworkmicrosoft.NET Frameworkcom/library/en-us/cpref/html/frlrfsys temconsoleclasstopic.NET Frameworkasp