| kategória | ||||||||||
|
|
||||||||||
|
|
||
|
Egyszerű |
Nincs pointer Nincs ::, ., -> Egységes típus rendszer Boxing/Unboxing támogatás If csak Boolean lehet Ismétlődések kizárása (const <-> #define, stb.) |
|
Modern |
Decimal típus Garbage Collector (szemétgyűjtés) Exception (kivétel) Biztonság |
|
Objektum orientált |
Nincs többé global Alapban minden nonvirtual 'Internal' elérési típus Egyszeri öröklődés Delegálás (funkció pointerek) |
|
Típus biztos |
Inicializálás Biztonságos cast-olás Túlcímzés ellenőrzés Túlcsordulás ellenőrzés |
|
Verziók |
Komponensek Verzió számozás |
|
Kompatibilis |
NGWS Common Language Specifiaction COM, COM+ OLE Automation Platform Invocation Services |
|
Rugalmas |
Unsafe metódusok Unsafe memória |
|
JIT |
Erősen optimalizált IL kód, lassú fordítás |
|
EconoJIT |
Gyors konverzió, kód cache |
|
PreJIT |
Ellenőrzött natív kód |
|
Primitív Típusok |
Bool, char, byte, short, int, long, float, double, string, object |
|
Tömbök |
Ismert dimenzió, lehet többszörös is Alsó határ: 0 |
|
Típusok |
Abstract vagy sealed Nulla vagy több interface Egyszeres öröklődés Overriding és hiding létezik Fields, methods, events, types Constructors Belső láthatóság Öröklődés: System.ValueType / System.Enum |
|
Típus members |
Hide vagy override Argument és return type CLS Constructor, metódus, property felülírható 232b12c Abstract members |
|
Metódusok |
Static, virtual, instance Final vagy nem Final |
|
Mezők |
Static vagy nonstatic |
|
Property-k |
Get és Set metódusok Indexelhető |
|
Enumerations |
Byte, short, int, long Nincs interface |
|
Kivételek |
Throw és catch, finalize COM Exceptions |
|
Interface-k |
Öröklődés |
|
Events |
Add és Remove metódusok Öröklődik: System.Delegate |
|
Delegates |
Created és Invoked |
|
Identifiers |
Nincs case sensitivity! |
|
Using System; Class HelloWorld |
|
Using System; Class InputOutput ", strName); } |
Részletes, futó kódok a Komponensek építése részben találhatóak ( és
Sbyte |
8 bit signed |
|
|
Byte |
8 bit unsigned |
|
|
Short |
16 bit signed |
|
|
Ushort |
16 bit unsigned |
|
|
Int |
32 bit signed |
|
|
Uint |
32 bit unsigned |
|
|
Long |
64 bit signed |
|
|
Ulong |
64 bit unsigned |
|
|
Nincs többé nemnulla igaz
|
char chSomeChar = 'A'; chSomeChar = '\x0065'; chSomeChar = '\u0065'; chSomeChar = (char)65; nSomeInt = (int)'A'; |
|
|
|
|
|
|
|
|
|
|
|
Null |
|
\a |
Alert |
|
\b |
Backspace |
|
\f |
Form feed |
|
\n |
New line |
|
\r |
Carriage return |
|
\t |
Horizontal tab |
|
\v |
Vertical tab |
Float |
|
1.5x10-45 |
3.4x1038 |
Double |
|
5x10-324 |
1.7x10308 |
Pozitív és negatív nulla
Pozitív és negatív végtelen
NaN
Nem nulla értékek
Decimal |
|
1.0x10-28 |
7.9x1028 |
|
struct IP class Test ...", myIP.b1, myIP.b2, myIP.b3, myIP.b4); } struct Point |
|
enum MonthNames ; enum MonthNames ; enum MonthNames ; enum MonthNames : byte ; |
0-val indul, típusa int. Lehetséges típusok: long, int, short, byte
Alapclass az összes típushoz.
|
Object theObj = 123; |
Lásd Class Modifikátorok (
|
Interface Iface class Cface:Iface int a class Test |
Lásd Events (
|
String myString = "text"; MyString = "text" + " more text"; char chFirst = myString[0]; if (myString == yourString) |
|
String[] arrArray = ; int[,] arr = , , }; int[,] myArr = new int[5,3]; int[][] my2Arr = new int[5]; my2Arr[0] = new int[4]; int[] SingleDim; int[,] TwoDim; int [][] Jagged; SingleDim = new int[20]; TwoDim = new int[,],}; Jagged = new int[1][]; |
|
double Value; // Boxing object BoxedValue = Value; |
|
// default constructor class TestClass // default // parameterized constructor class TestClass public TestClass(string strName, int nAge) public ~TestClass() // destructor, called by GC ! public Release() // call it by hand |
|
public int Square(int n) Console.WriteLine(Square(25)); // object always pass a reference by value |
|
void Square(ref int n) int n = 20; // init Square(ref n); Console.WriteLine(n); |
|
void Square(int n, out int nn) int n; // noninit Square(20, out n); Console.WriteLine(n); |
|
class Triangle class RightTriangle:Triangle class Test |
|
class Triangle class RightTriangle:Triangle class Test |
|
Public class Person : |
|
Public class House set } public int this[int nIndex] } class Test |
|
// Transaction logic [Transaction(TransactionOption.Required)] [PersonFirstName] String
Vorname; // custom attributes // Typeof(<object-expr>).GetCustomAttributes(); class PersonFirstNameAttribute
: Attribute |
|
// forward declaration with delegation public delegate void EventHandler(string strText); class EventSource class TestApp public static void CacthEvent(string strText) public void InstanceCatch(string strText) |
|
Abstract |
Nem lehet instace-t csinálni, implementálni kell az abstract metódusokat |
|
Sealed |
Nem lehet örökölni |
|
abstract class AbstractClass sealed class DerivedClass : AbstractClass public class TestApp |
|
Abstract |
Method és accessor |
Nem tartalmaz implementációt. Implikálisan virtual, és öröklődéskor meg kell adni az override Kulcsszót. |
|
Const |
Field és local
variable |
Nem tartalmazhat referenciát, fordítási időben kiértékelődik |
|
Event |
Field és property |
Class eseményeihez kliens kód hozzákötése |
|
Extern |
Method |
Külső implementáció |
|
Override |
Method és accessor |
Módósítani egy abstract definiálású elemet |
|
Readonly |
Field |
Csak deklaráció és contstructor változtathatja meg |
|
Static |
Field, method,
property, operator és constructor |
A Class-hoz és nem az instance-hez tartozik |
|
Virtual |
Method és accessor |
Öröklődéssel felülírható |
|
Public |
Mindenhonnan elérhető |
|
Protected |
A Classból és minden származottból |
|
Private |
Csak a Classból, leszármazottból sem |
|
Internal |
Ugyanabból az applikációból |
|
class NestedIfApp char chLetter = args[0][0]; if (chLetter >= 'A') if (chLetter <= 'Z') is uppercase",chLetter); Return 0; } chLetter = Char.FromString(args[0]); if (chLetter >= 'a' && chLetter <= 'z') Console.WriteLine(' is lowercase",chLetter); if (Char.IsDigit((chLetter = args[0][0]))) Console.WriteLine(' is digit",chLetter); return 0; } |
|
switch (nInt) |
String is használható !
|
for (initializer; condition; iterator) // code if (condition2) // code |
|
// foreach (Type identifier in expression) class EnviromentDumpApp public static void { Idictionary envvars = Environment.GetEnvironmentVariables(); Console.WriteLine("Count: ", envvars.Keys.Count); Foreach (String strKey in envvars.Keys) { Console.WriteLine(" = ", strKey, envvars[strKey].ToString()); } } // Implements IEnumerable with GetEnumerator() Point[] Points = GetPoints(); |
|
while (conditional) |
|
do while (condition); |
|
lock(<object>); |
|
// Programatic Exception Checking checked unchecked |
|
Try catch (OverflowException oe) Console.WriteLine("Computing caused overflow", nComputeTo); Return Console.WriteLine("! is ", nComputeTo, nFactorial); |
|
bool bAllFine = false; try bAllFine = true; finally if (!bAllFine) Console.WriteLine(" caused", nComputeTo, nFactorial); Else Console.WriteLine("! is ", nComputeTo, nFactorial); |
|
class CatchIT catch(DivideByZeroException divEx) catch(Exception Ex) finally } |
Megcserélve a kettő catch sorrendjét, a második sosem hajtódna végre
|
Exception |
Base class minden exception object-hez |
|
SystemException |
Base class minden exception object-hez, ami runtime |
|
IndexOutOfRangeException |
Kiindexelve egy tömbből |
|
NullReferenceException |
NULL objektum referenciálva |
|
InvalidOperationException |
Ha a hívás, figyelembe véve a class aktuális helyzetét, érvénytelen |
|
ArgumentException |
Base class minden argumens alapú exception object-hez |
|
ArgumentNullException |
Ha az argument NULL ahol nem megengedett |
|
ArgumentOutOfRangeException |
Ha az argument kívűl van a megengedett határokon |
|
InteropException |
NGWS-n kívüli exceptionok |
|
ComException |
A COM klasszikus HRESULT információt tartalmazó exception-ja |
|
SEHException |
Exception enkapszulálva a Win32 Structured Exception Handling információt |
|
throw new ArgumentException("Argument can\'t be 5"); |
|
Try catch (OverflowException oe) Console.WriteLine("Computing caused overflow", nComputeTo); throw; // rethrowing |
|
public class MyImportantException:Exception public MyImportantException(string message):base(message) public MyImportantException(string message, Exception inner):base(message, inner) public class ExceptionTestApp public static void catch (Exception e) } |
Adjunk jól érthető leírást, amikor eldobjuk a kivételt
Csak akkor dobjunk kivételt, ha az eset kivételes; vagyis, amikor a normális visszatérési érték nem elégséges
Normális vagy várható hibák jelzésére ne használjunk kivételt
Dobjunk ArgumentException -t, ha nem jó paramétert kapunk
Dobjunk InvalidOperationException -t, ha nem megfelelő státuszban van az objektumunk
Dobjuk mindig a legmegfelelőbb kivételt
Használjunk láncba fűzött kivételeket. Segítenek követni a kivétel-fát
Ne dobjunk NullReferenceException vagy IndexOutOfRangeException kivételt
Találat: 1510