easy c sharp in arabic.pdf

100
1

Upload: everahlawy

Post on 14-Apr-2015

69 views

Category:

Documents


6 download

TRANSCRIPT

Page 1: Easy C sharp in Arabic.pdf

1

Page 2: Easy C sharp in Arabic.pdf

2

C#.Net

خالد السعداني: من إعداد

Page 3: Easy C sharp in Arabic.pdf

3

��������������������������������������

������������������������������

�����������������������������

�������������������������

71و 70: األحزاب

Page 4: Easy C sharp in Arabic.pdf

4

� �

�����

Page 5: Easy C sharp in Arabic.pdf

5

Page 6: Easy C sharp in Arabic.pdf

6

خالد السعداني :الكامل اإلسم

05-51-07-0673: الهاتف

بمدينة الفقيه بن صالح ، المغرب 18/05/1989 مواليدمن

متخصص في التنمية المعلوماتيةتقني

: البرمجة ب: المهنية فاءاتكال

vb.net,c#.net,C++,C,Java(J2ee)

:للويب وبالنسبة

Asp.net,PHP,Html,JavaScript,Ajax,CSS,jQuery

: قواعد البياناتأما

MS Access,MS SQL Server,MySQL

Page 7: Easy C sharp in Arabic.pdf

7

�������������

������

Page 8: Easy C sharp in Arabic.pdf

8

Page 9: Easy C sharp in Arabic.pdf

9

�������������������������

�����������

� �

[email protected]

Page 10: Easy C sharp in Arabic.pdf

10

12

1 ..................................................... 15

15 ............................................................................ المتغیرات 1.1

15 ................................................... : شارب السي بلغة برنامج بنیة 1.2

16 ..................................................................... : البیانات أنواع 1.3

18 ............................................................................ الثوابت 1.4

18 ............................................................................ : الروابط 1.5

20 ........................................................... اإلخراج و اإلدخال أوامر 1.6

21 .................................................................... : الشرطیة البنیة 1.7

25 .................................................................... :التكراریة البنیة 1.8

Les charactéres d’échappement(Escape characters) ............. 29 اإلختصار رموز1.9

2 ............................................................... 33

Les tableaux (Arrays) .................................... 33 المصفوفات .1

Les listes(List) ..................................................... 38 اللوائح .2

Enumerations(Enum) ........................................ 39 المعددات .3

Structure (Struct) ............................................... 40 التراكیب .4

Les fonctions (functions) .................................... 41 الدوال .5

3. ........................................................... 46

52 ................................. :(visibility) البرمجیة الكائنات تعریف حدود .1

assemblies ....................................................... 53 المجمعات 2

Les espaces des noms(namespaces) ..... 53 األسماء مجاالت .3

instanciation .............................................. 54 الفئات استنساخ .4

static ................................................................... 54 استعمال .5

Page 11: Easy C sharp in Arabic.pdf

11

Constructors ..................................................... 55 المشیدات .6

Properties .................................................. 57 الفئات خصائص 7

60 ............................................................... : األخطاء مع التعامل .8

62 ............................................................. : الكائنات من مصفوفة .9

overloading (la surcharge) ......................... 64 التعاریف تعدد .10

Operators overloading : ............ 65للروابط بالنسبة التعاریف تعدد 11

L’héritage (Inheritance) ...................................... 68 الوراثة .12

Les classes abstraites(Abstract classes) 70 المجردة الفئات .13

Les classes scellés (Sealed classes) ........ 71 المغلقة الفئات .14

Les methodes virtuelles (Virtual Methods) ................................. 71 الوھمیة الدوال.15

new ........................................................................ 73 الكلمة .16

Le polymorphisme (Polymorphism)............. 76األشكال تعدد .17

Les interfaces (Interfaces) ............................... 77 الواجھات .18

Les delegates (delegates) .............................. 80 المفوضات .19

délégués multicast (multicast)................ 84 تعددالم التفویض .20

Les événements (events) .................................. 86 األحداث .21

Les méthodes anonymes (Anonymous methods) ............... 91 المجھولة اإلجراءات.22

Les expressions lambda(lambda expressions) .......................... 95 المدا العبارات.23

97

98

Page 12: Easy C sharp in Arabic.pdf

12

Page 13: Easy C sharp in Arabic.pdf

13

20002002

Framework 1.0

Framework

2.03.03.54.0

4.0

Page 14: Easy C sharp in Arabic.pdf

14

Page 15: Easy C sharp in Arabic.pdf

15

1 المتغیرات 1.1

Integer a ; Integer b ; A=3 ; B=5 ; Write(a+b) ;

a b

:لغة السي شارب بنیة برنامج ب 1.2

using System; class FirstProgram { static void Main() {

//یكتب الكود هنا } }

Main

systemFirstProgram

Page 16: Easy C sharp in Arabic.pdf

16

:أنواع البیانات 1.3

128127 1 sbyte System.SByte

0255 1 byte System.Byte

3276832767 2 short System.Int16

2147483648 214748364 7 4 int System.Int32

04294967295 4 uint System.Uint32

9223372036854775807 9223372036854775808 8 long System.Int64

3,4E+38 -3,4E+38 4 float System.Single

1,79E+308 -1,79E+308 8 double System.Double

7,9E+29 -7,9E+29 16 decimal System.Decimal

(UTF-16) 2 char System.Char

(true / false) 4 bool System.Boolean

* string System.String

using System ; class FirstProgram { static void Main() { int a; int b; a = 3; b = 5; Console.Write("La somme de ces deux nombres est " + (a + b)); Console.ReadKey(); } }

Page 17: Easy C sharp in Arabic.pdf

17 using System ; class FirstProgram { static void Main() { int a=3,b=5; Console.Write("La somme de ces deux nombres est " + (a + b)); Console.ReadKey(); }

write() ReadKey()

console

Page 18: Easy C sharp in Arabic.pdf

18

الثوابت 1.4

!const

const int a = 5;

:الروابط 1.5

1

%

using System ; class Operators { static void Main() { int a = 10, b = 6, Somme, Différence, Produit; float Division; Somme = a + b; Différence = a - b; Produit = a * b; Division = a / b; Console.Write("Somme={0}, Dif={1}, Produit={2}, Div={3}", Somme, Différence, Produit, Division); Console.ReadKey(); } }

Page 19: Easy C sharp in Arabic.pdf

19 { }

2

||

Var2 Cond var1 cond ? var1 : var2

3

is

<

>

<= , >=

!=

==

4

+= ,- =, /=, *=, %=

++ , - -

Page 20: Easy C sharp in Arabic.pdf

20

أوامر اإلدخال و اإلخراج 1.6

write

ReadLine()

using System ; class ReadValue { static void Main() { string Name; Console.Write("Enter your name "); Name = Console.ReadLine(); Console.Write("Hello " + Name); Console.ReadKey(); } }

using System ; class ReadValue { static void Main() { int Age; Console.Write("Enter your Age "); Age = Convert.ToInt32(Console.ReadLine()); Console.Write("Your age is " + Age); Console.ReadKey(); } }

ReadLine()

ToInt32Convert

Page 21: Easy C sharp in Arabic.pdf

21

:البنیة الشرطیة 1.7

1 if

if (Condition == true) { //instruction }

Condition

instruction

Page 22: Easy C sharp in Arabic.pdf

22

static void Main() { //This is a comment //This is another Comment }

static void Main() { /* This is a comment This is another Comment */ }

if (Condition == true) { //instructions } else { //other instructions }

if (Condition == value) { // instructions إذا حتقق الشرط األول } else if (Condition == OtherValue) { //other instructions إذا حتقق الشرط الثاني } else { //Other instructions إذا مل یتحقق أي شرط }

Page 23: Easy C sharp in Arabic.pdf

23

else if

using System ; class Condition { static void Main() { int Age; Console.WriteLine("How old are you? : "); Age=Convert.ToInt32(Console.ReadLine()); if(Age<=18 && Age>0) //راجع الروابط املنطقیة) و(تعين && { Console.Write("You are young"); } else if (Age>=18 && Age<140) { Console.Write("You are adult"); }else { Console.Write("Error age !!"); } Console.ReadKey(); } }

2 Switch

ifstatic void Main() { switch (Expression) // املتغري الذي سنجري علیه التحقیق { case 1: //نقوم مبا یلي 1إذا كانت قیمته هي //instructions; break; case 2: //نقوم مبا یلي 2إذا كانت قیمته هي //other instructions break; default: // األوامر اإلفرتاضیة يف حالة عدم ختقق أي شرط //Defalut instructions break; } }

Page 24: Easy C sharp in Arabic.pdf

24

using System ; class Switching { static void Main() { string Job; Console.Write("What's your job ?"); Job = Console.ReadLine(); switch (Job) { case "Doctor" : Console.Write("You are a doctor"); break; case "Professor" : Console.Write("You are a Professor"); break; default: Console.Write("Job unKnown !!"); break; } Console.ReadKey(); }

break

3

Expression ? Valeur1 :valeur2

Expression true valeur1

valeur2

Page 25: Easy C sharp in Arabic.pdf

25

class Ternaire { static void Main() { string Name; string Expression; Console.WriteLine("What's your Name?"); Name = Console.ReadLine() Expression = Name == "khalid"?"It’s my name!":"Nice to meet you !!" + Name; Console.WriteLine(Expression); Console.ReadKey(); }}

Name

khalid it’s my name Nice to meet

you

:البنیة التكراریة 1.8

1

For

for (i = 0; i < 6; i++) { Console.WriteLine("Numéro" + i); }

i0

6 i1

0

Page 26: Easy C sharp in Arabic.pdf

26

using System ; class Boucles { //Programme pour calculer le factoriel static void Main() { int i,Nombre; int Factoriel = 1; Console.WriteLine("Donner un nombre"); Nombre = Convert.ToInt32(Console.ReadLine()); for (i = Nombre; i > 0; i--) { Factoriel = Factoriel *i ; } Console.WriteLine("Le factoriel de ce nombre est " +

Factoriel); Console.ReadKey(); }

iNombre Factoriel1

i

Factoriel1i

330

Factorieli

Page 27: Easy C sharp in Arabic.pdf

27

Factoriel10

0

2

While

while (Condition) // الشرط الذي بتحققه نكرر األوامر { //instructions األوامر اليت نقوم بتكرارها }

while

goto

using System ; class Boucles { static void Main() { int Valeur; Point: Console.WriteLine("Devinez la valeur "); Valeur = Convert.ToInt32(Console.ReadLine()); while (Valeur != 5) { Console.WriteLine("La valeur est fausse réessayer "); goto Point; } Console.WriteLine("Vous avez gagné !!"); Console.ReadKey(); } }

Page 28: Easy C sharp in Arabic.pdf

28

5while

5Point

gotovaleur 5

5

for

while

3

Do

while

do { //Instruction األوامر اليت نرغب يف تكرارها } while (Condition); //الشرط الذي بتحققه نعید األوامر

class Boucles { static void Main() { int Number=0; do { Console.WriteLine("Numéro "+ Number++); } while (Number>0 && Number<=10); Console.ReadKey(); } }

110

Number0101

Page 29: Easy C sharp in Arabic.pdf

29

4 Foreach

5

break

continue

using System ; class Boucles { static void Main() { int i; for (i = 0; i < 6; i++) { Console.Write(i); if (i< 3) continue;

break; } Console.ReadKey(); }

s)characterLes charactéres d’échappement(Escapeرموز اإلختصار 1.9

console.writeLine()

Page 30: Easy C sharp in Arabic.pdf

30

using System ; class Program { static void Main() { Console.WriteLine(" **Menu**"); Console.WriteLine(" 01-Csharp"); Console.WriteLine(" 02-VB"); Console.WriteLine(" 03-Java"); Console.ReadKey(); } }

class Program { static void Main() { Console.WriteLine("\t\t**Menu**\n\n\t\t01-Csharp\n\t\t02-VB\n\t\t03-Java"); Console.ReadKey(); } }

Page 31: Easy C sharp in Arabic.pdf

31

\

\

\ \\

Beep \a

\n

Tabulation \t

\b

Page 32: Easy C sharp in Arabic.pdf

32

Page 33: Easy C sharp in Arabic.pdf

33

2 Les tableaux (Arrays)ات المصفوف .1

Type[] Array=new Type[N];

TypeArray N

using System ; class Tableau { static void Main() { int[] Array = new int[5];// عناصر 5قمنا باإلعالن عن مصفوفة هبا int i,j,Temp; for (i = 0; i < Array.Length; i++) //املصفوفةإىل ایة 0انطلقنا من { Console.WriteLine("Donner l\'element " + i); // بدأنا بقراءة العناصر املدخلة

Array[i] = int.Parse(Console.ReadLine()); // convert.ToInt32 هلا نفس دور

} for (i = 0; i < Array.Length; i++)

//خر عنصرر باملصفوفة إىل آصینطلق من أول عن التكرار األول for (j = i + 1; j < Array.Length; j++)

//ر باملصفوفة إىل آخر عنصرصعن ثانینطلق من الثانيالتكرار {

Page 34: Easy C sharp in Arabic.pdf

34

if (Array[i] > Array[j]) // نقارن بني عنصرین متتابعني //إذا كان العنصر األول أكري من العنصر الثاني

{ Temp = Array[i];/* يف املتغري األولخنزن قیمة العنصر Temp */ Array[i] = Array[j]; // يف مكان الثانيو قیمة العنصر

األول العنصر Array[j] = Temp; // مث يف األخري خنزن قیمة املتغري يف مكان

الثانيالعنصر } } { } for (i = 0; i < Array.Length; i++) //نقوم هبذا التكرار من أجل إظهار مجیع قیم املصفوفة بالرتتیب اجلدید

{ Console.WriteLine("Le tri de ces nombres par ordre croissant est : " + Array[i]); } Console.ReadKey(); }

...... 0 1 2 3 n

0nindex

Page 35: Easy C sharp in Arabic.pdf

35

string[] Names=new string[4]; Names[0] = "Abu bakr"; Names[1] = "Omar"; Names[2] = "Ali"; Names[3] = "Othman";

0Abu bakr

Abu bakr Omar Ali Othman

0 1 2 3

foreachتعمال اس

foreach (TypeVariable variable in Collection) { //Instructions }

Page 36: Easy C sharp in Arabic.pdf

36

using System ; class Program { static void Main() { string[] Name = new string[2]; Name[0] = "mohamed"; Name[1] = "khalid"; foreach (string Nom in Name) { Console.WriteLine(Nom.ToUpper()); } Console.ReadKey(); } }

MOHAMED KHALID

int[,] Array = new int[3, 4];

(0,0) (0,1) (0,2) (0,3) (1,0) (1,1) (1,2) (1,3) (2,0) (2,1) (2,2) (2,3)

Page 37: Easy C sharp in Arabic.pdf

37

using System ; class Matrice { static void Main() { int[,] Matrice = new int[3, 4]; int i, j; for(i=0;i<=2;i++) { for (j = 0; j <= 3; j++) { Console.WriteLine("Donner l\'élément :(" + i + "," + j + ")"); Matrice[i, j] = int.Parse(Console.ReadLine()); } } for (i = 0; i <= 2; i++) { for (j = 0; j <= 3; j++) { Console.WriteLine("La valeur de l\'élément :(" + i + "," + j + ") est " + Matrice[i,j] ); } } Console.ReadKey(); }

char[,,] TriDimensions = new char[2, 3, 5];

Page 38: Easy C sharp in Arabic.pdf

38

Les listes(List)اللوائح .2

List<Type> nomDeLaListe = new List<Type>();

TypenomDeLaListe

Add

List<String> Names = new List<string>(); Names.Add("Mohamed"); Names.Add("Khalid");

List<String> Names = new List<string> { "Mohamed", "Khalid" };

foreach

using System; class Program { static void Main(string[] args) { List<String> Names = new List<string> { "Mohamed", "Khalid" }; foreach (String Name in Names) { Console.WriteLine(Name); } Console.ReadKey(); } }

Page 39: Easy C sharp in Arabic.pdf

39

clear

count

)EnumEnumerations( المعددات .3

0

enum Niveau { Facile, Moyen, Difficile };

Niveau

0

Niveau NiveauJeu;

Page 40: Easy C sharp in Arabic.pdf

40

class Enumerations { enum Niveau{Facile,Moyen,Difficile}; static void Main() { Niveau NiveauJeu = Niveau.Facile; Console.WriteLine("*************Niveau du jeu**************"); if (NiveauJeu == Niveau.Facile) { Console.WriteLine("Ce niveau est facile "); } } }

Structure (Struct) التراكیب .4

struct Personne { string Nom; string Adresse; short Age; }

Personne

Page 41: Easy C sharp in Arabic.pdf

41

class Structure { struct Personne { public string Nom; public string Adresse; public short Age; } static void Main() { Personne Person; Console.WriteLine("Donner votre nom"); Person.Nom = Console.ReadLine(); Console.WriteLine("Donner votre Adresse"); Person.Adresse = Console.ReadLine(); Console.WriteLine("Donner votre Age"); Person.Age =Convert.ToInt16(Console.ReadLine()); //Affichage Console.WriteLine("Votre nom est:{0} , votre adresse est: {1} " + " , votre Age est: {2}" , Person.Nom, Person.Adresse, Person.Age); Console.ReadKey(); } }

Personne

Nom Adresse Age

Les fonctions (functions) الدوال 5

Page 42: Easy C sharp in Arabic.pdf

42

Main()

Main()

Main()

!!

TypeDeFonction NomDeFonctions(Parametres) { //instructions return valeur; }

Static int Somme(int N1, int N2) { return N1 + N2; }

return

N1.N2

Somme(3, 5);

Page 43: Easy C sharp in Arabic.pdf

43

int Som = Somme(12, 55);

Console.WriteLine(Somme(3, 8));

using System ; class Somme {

//La fonction static int Somm(int N1, int N2) { return N1 + N2; } static void Main() { int N1, N2; Console.WriteLine("Donner le premier nombre :"); N1 = int.Parse(Console.ReadLine()); Console.WriteLine("Donner le deuxiéme nombre :"); N2 = int.Parse(Console.ReadLine()); Console.WriteLine("La somme de ces deux nombres est :" + Somm(N1, N2)); Console.ReadKey(); } }

return

voidMain()

Page 44: Easy C sharp in Arabic.pdf

44

using System ; class WithoutReturn { static void MyFunction() { string Nom; Console.WriteLine("Entrer votre nom :"); Nom = Console.ReadLine(); Console.WriteLine("Bonjour " + Nom); Console.ReadKey(); } static void Main(string[] args) { MyFunction(); } }

Page 45: Easy C sharp in Arabic.pdf

45

Page 46: Easy C sharp in Arabic.pdf

46

class Arkan { public string Achahada; public string Assalat; public string Assawm; public string Azzakat; public string Alhaj; }

Arkan ArkanClass;

3

classes

Arkan

struct Arkan { public string Achahada; public string Assalat; public string Assawm; public string Azzakat; public string Alhaj; }

Arkan ArkanStruct;

Page 47: Easy C sharp in Arabic.pdf

47

(value)

(reference)

Le tas La pile

class int

Array char

string boolean

delegatestruct

enum

class Arkan { public string Achahada; public string Assalat; public string Assawm; public string Azzakat; public string Alhaj; }

Reference

Arkan ArkanStruct ;

Arkan ArkanClass ;

(Achahada,Assalat,Assawm,A

zzakat,Alhaj)

المفتاح

referenceالمرجع

valueالقیمة

Page 48: Easy C sharp in Arabic.pdf

48

using System ; class FunctionByValue { static void Function(int Number) { Number = 3; Console.WriteLine("La valeur du variable maintenant est :" + Number); } static void Main() { int Num = 10; Function(Num); Console.WriteLine("La valeur d\'origine est :" + Num); Console.ReadKey(); } }

function Num 3

Num10

La valeur du variable maintenant est :3 La valeur d'origine est :10

ref

Page 49: Easy C sharp in Arabic.pdf

49

La valeur du variable maintenant est :3 La valeur d’origine est :3

using System ; class FunctionByReference { static void Function(ref int Number) { Number = 3 ; Console.WriteLine(« La valeur du variable maintenant est : » + Number) ; } static void Main() { int Num = 10 ; Function(ref Num) ; Console.WriteLine(« La valeur d\’origine est : » + Num) ; Console.ReadKey() ; } }

refNum

outNum

out

Page 50: Easy C sharp in Arabic.pdf

50

using System; class Program { static void Function(out int Number) { Number = 3 ; Console.WriteLine(" La valeur du variable maintenant est : " +Number) ; } static void Main() { int Num ; Function(out Num) ; Console.WriteLine(" La valeur d\'origine est : " + Num) ; Console.ReadKey() ; } }

public class Exemple {

//;Type1 Attribut املتغري األول //;Type2 Attribut2 املتغري الثاني

//;Type3 Attribut املتغري الثالث

//()Type Methode1 الدالة أو اإلجراء األول{ }

//()Type Methode2 الدالة أو اإلجراء الثاني{ }

}

Page 51: Easy C sharp in Arabic.pdf

51

class Livre { private string Titre; private string Auteur; private double Prix; public void Initialiser(string titre, string auteur, double prix) { this.Titre = titre; this.Auteur = auteur; this.Prix = prix; } public void Information() { Console.Write("Le titre de livre est :{0}, son auteur est :{1}",Titre,Auteur); } }

TitreAuteurPrixLivre

Initialiser

InitialisertitreRyad Assalihin

Titre Initialiser

Information

initialiser

Initialiser

This

Page 52: Easy C sharp in Arabic.pdf

52

Le titre de livre est :kalila wa dimna,son auteur est : Abdulah bno lmoqafaa

Livre MonLivre = new Livre();

Livrenewinstance

MonLivre

using System ; class Test { static void Main() { Livre MonLivre = new Livre(); MonLivre.Initialiser("Kalila wa dimna", "Abdulah bno lmoqafaa",75); MonLivre.Information(); Console.ReadKey(); } }

Initialiser

Information

:(visibility)الكائنات البرمجیة تعریف حدود .1publicstatic

Page 53: Easy C sharp in Arabic.pdf

53

Public

Private

Protected

Internal

assembly

assembliesالمجمعات 2assembly

exedllApplicationexe

Bibliothéquedll

Les espaces des noms(namespaces)مجاالت األسماء .3using

System

consoleconvertIOCollections

using

System.Console.WriteLine()

Console.WriteLine()

Page 54: Easy C sharp in Arabic.pdf

54

instanciationاستنساخ الفئات 4

New

Personne Person = new Personne();

staticاستعمال .5

using System; class Personne { static public int Age; static public int returnAge() { return Age; } } class Test { static void Main() { Personne.Age = 21; int Age = Personne.returnAge(); Console.WriteLine(Age); Console.ReadKey(); } }

agereturnAgePersonne

Static

Page 55: Easy C sharp in Arabic.pdf

55

Constructors المشیدات .6

Inistialiser

void

class object=new class(arg1,arg2,....,argN);

instanciation

class object=new class();

Article

attributesMethodesconstructors

CodePrixType

Page 56: Easy C sharp in Arabic.pdf

56

using System.Text; class Article { //Attributes املتغريات الداخلیة private int Code; private string Type; private double Prix; //Constructor املشید public Article(int code, string type, double prix) { this.Code=code; this.Type = type; this.Prix = prix; } //Methode الدالة احلسابیة public double CalculPrix(int Quantite) { double Montant; Montant = Quantite * Prix; return Montant; } }

CalculPrix

Montant

using System; class Test { static void Main() { Article MonArticle = new Article(1, "Ordinateur", 4500); double Montant = MonArticle.CalculPrix(4); Console.Write("Le montant de cet article est : " + Montant); Console.ReadKey(); } }

Page 57: Easy C sharp in Arabic.pdf

57

MonArticle

CalculMontantMonArticle4

Propertiesخصائص الفئات 7

getset

public Type Property { get { return Attribute; } set { Attribute = value; } }

TypeProperty

getset

Code

PropertyCode

Page 58: Easy C sharp in Arabic.pdf

58

using System.Text; class Article { //Attributes املتغريات الداخلیة private int Code; private string Type; private double Prix; //Constructor املشید public Article(int code, string type, double prix) { this.Code=code; this.Type = type; this.Prix = prix; } //Methode الدالة احلسابیة public double CalculPrix(int Quantite) { double Montant; Montant = Quantite * Prix; return Montant; } //Properties اخلاصیات public int PropertyCode { get { return Code; } set { Code = value; } } public string PropertyType { get { return Type; } set { Type = value; } } public double PropertyPrix { get { return Prix; } set { Prix = value; } } }

Page 59: Easy C sharp in Arabic.pdf

59

using System; class Test { static void Main() { Article MonArticle = new Article(1, "Ordinateur", 4500); Console.Write("Le code de l\'article est :{0}," +"son type est :{1},son prix unitaire est:{2}" ,MonArticle.PropertyCode,MonArticle.PropertyType, MonArticle.PropertyPrix ); Console.ReadKey(); } }

get

set

using System; class Test { static void Main() { Article MonArticle = new Article(1, "Ordinateur", 4500); MonArticle.PropertyCode = 100; MonArticle.PropertyType = "Télévision"; MonArticle.PropertyPrix = 5000; Console.Write("Le code de l\'article est :{0}," + "son type est :{1},son prix unitaire est:{2}" , MonArticle.PropertyCode, MonArticle.PropertyType, MonArticle.PropertyPrix); Console.ReadKey(); } }

set

Page 60: Easy C sharp in Arabic.pdf

60

public double PropertyPrix { get { return Prix; } set { if (value == 0)Console.WriteLine("Le prix doit être"

"+ supérieur à 0"); else Prix = value; Console.WriteLine("Prix accepté !!!"); } }

Prix0

using System; class Test { static void Main() { Article MonArticle = new Article(1,"Ordinateur",4500); Console.WriteLine("Donner le nouveau prix de l\'article"); MonArticle.PropertyPrix = Convert.ToDouble(Console.ReadLine()); Console.ReadKey(); } }

PropertyPrix ReadLine()

:التعامل مع األخطاء .8

Page 61: Easy C sharp in Arabic.pdf

61

using System; class Test { static void Main() { int Age; Console.WriteLine("Donner votre age :"); Age = int.Parse(Console.ReadLine()); Console.ReadKey(); } }

Page 62: Easy C sharp in Arabic.pdf

62

try { //instructions } catch { //resultats }

using System; class Test { static void Main() { int Age; Console.WriteLine("Donner votre age :"); try { Age = int.Parse(Console.ReadLine()); } catch { Console.WriteLine("Il faut saisir une valeur numérique !!!!"); } Console.ReadKey(); } }

:مصفوفة من الكائنات .9

Information

Article

Page 63: Easy C sharp in Arabic.pdf

63

public void Information() { Console.WriteLine("Le Code de l\'article est :{0}" + ", Son Type est :{1},et son Prix est :{2}" + "", this.Code, this.Type, this.Prix); }

using System; class Test { static void Main() { Article[] MonArticle = new Article[3]; MonArticle[0] = new Article(1, "Ordinateur", 4500); MonArticle[1] = new Article(2, "Télévision", 5000); MonArticle[2] = new Article(1, "Téléphone", 250.50); for (int i = 0; i<MonArticle.Length; i++) { MonArticle[i].Information(); } Console.ReadKey(); } }

Information

Page 64: Easy C sharp in Arabic.pdf

64

overloading (la surcharge) تعدد التعاریف 10

ToString()Convert36

Page 65: Easy C sharp in Arabic.pdf

65

using System; class Ouvrier { متغريات الفئة // private int ID; private string Nom; تعدد التعاریف بالنسبة للمشیدات // public Ouvrier() { } public Ouvrier(int n1, string n2) { this.N1 = ID; this.N2 = Nom; } تعدد التعاریف بالنسبة للدوال // public void SearchInfo(int ID) { // } public void SearchInfo(string Nom) { // } }

SearchInfo

:verloading Operators oتعدد التعاریف بالنسبة للروابط 11

Page 66: Easy C sharp in Arabic.pdf

66

Complexe

3+2i,-5+12i,12+i ,…

i

Page 67: Easy C sharp in Arabic.pdf

67

using System; class Complexe { // )اجلزء احلقیقي و اجلزء اخلیايل (متغريات الفئة private int Reel, Imaginaire; مشید مبتغريات داخلیة من أجل إعطاء قیم ملتغريات الفئة// public Complexe(int reel, int imaginaire) { this.Reel = reel; this.Imaginaire = imaginaire; } // + إعادة تعریف الرایط public static Complexe operator +(Complexe C1, Complexe C2) { return new Complexe(C1.Reel + C1. Reel, C2. Imaginaire + C2.Imaginaire); } دالة من أجل إظهار النتیجة على شكل عدد عقدي // public string Affichage() { return(String.Format("{0}+{1}i",Reel,Imaginaire)); } }

Complexe

Complexe

operator

Affichage

Page 68: Easy C sharp in Arabic.pdf

68

using System; class Program { static void Main(string[] args) { Complexe c1 = new Complexe(3, 5); Complexe c2=new Complexe(4,6); Console.WriteLine("Le premier nombre complexe est:{0} , et le deuxiéme est :{1}",c1.Affichage(),c2.Affichage()); Console.WriteLine("La somme de ces deux complexes est " + (c1 + c2).Affichage()); Console.ReadKey(); } }

!=

||

L’héritage (Inheritance) الوراثة .12

Personne

)MedecinFormateur

Personne

Page 69: Easy C sharp in Arabic.pdf

69

Personne

public class Personne { private string Nom; private string Adresse; private string Sexe; private short Age; }

public class ClassFille:ClasseMere { }

Page 70: Easy C sharp in Arabic.pdf

70

PersonneMedecin

// Medecinالفئة

public class Medecin : Personne { private string Spécialité; }

// Formateurالفئة

public class Formateur : Personne { private string Filiére; }

s(Abstract eLes classes abstraitالفئات المجردة .13 classes)

MustInheritAbstract

abstract class Personne { private string Nom; private string Adresse; private string Sexe; private short Age; }

Personne

Page 71: Easy C sharp in Arabic.pdf

71

class Formateur:Personne { private string Filiére; }

Personne

classesscellés (Sealed classesLes(المغلقة الفئات .14sealed

sealed class Personne { } // sealed سینتج عن هذه الوراثة خطأ ألن الفئة األم معلن عنها ب class Medecin : Personne { }

Les methodes virtuelles (Virtualالدوال الوھمیة .15Methods)

PersonneTravail()

Ouvrier Personne

Travail()Ouvrier

Page 72: Easy C sharp in Arabic.pdf

72

VirtualTravail

override

class Personne { string Nom; string Adresse; string Sexe; short Age; public virtual void Travail() { Console.WriteLine("Je travaille"); } } class Ouvrier : Personne { public override void Travail() { base.Travail(); Console.WriteLine("Et plus précisément je suis un ouvrier"); } }

base

Je travaille Et plus précisément je suis un ouvrier

Page 73: Easy C sharp in Arabic.pdf

73

newالكلمة .16override

override

class Art { Public virtual void Description() { Console.WriteLine("l\'art est la classe mére"); } } class Theatre:Art { new public void Description() { Console.WriteLine("Le théatre est une classe fille"); } }

using System; class Test { static void Main() { Theatre theatre = new Theatre(); Art art = theatre; art.Description(); Console.ReadKey(); } }

Page 74: Easy C sharp in Arabic.pdf

74

Art

new

l'art est la classe mére

newoverride

هذه هي الفئة األم // class Art { public virtual void Description() { Console.WriteLine("l\'art est la classe mére"); } }

// وهذه فئة مشتقة

class Theatre:Art { new public void Description() { Console.WriteLine("Le théatre est une classe fille"); } }

// وهذه فئة مشتقة أخرى class Cinema:Art { public override void Description() { Console.WriteLine("la cinéma est une classe fille"); } }

Page 75: Easy C sharp in Arabic.pdf

75

Cinema

override

newoverride

using System; class Test { static void Main() { Theatre theatre = new Theatre(); Cinema cinema = new Cinema(); Art art = new Theatre(); Console.WriteLine("Ici on a utilisé <--new-->\n"); art.Description(); art = new Cinema(); Console.WriteLine("Ici on a utilisé <--override-->\n"); art.Description(); Console.ReadKey(); } }

new

Cinemaoverride

Ici on a utilisé <--new--> L'art est la classe mére'art est la classe mére

Ici on a utilisé <--override-->

la cinéma est une classe fille

Page 76: Easy C sharp in Arabic.pdf

76

Le polymorphisme (Polymorphism) األشكالتعدد 17

!!!!

SportTennisAmation()

Sport

static void Amation(Sport S) { // }

Sport

using System; class Program { static void Main() { Teenis T = new Teenis(); Amation(T); } }

TennisSport

Page 77: Easy C sharp in Arabic.pdf

77

Les interfaces (Interfaces)الواجھات 18

interfacesabstract

implementation

interface Quadrilatére { int Longueur { get; set; } int Largeur{get;set;} float Surface(); }

Quadrilatére

Properties

class Rectangle:Quadrilatére { }

Page 78: Easy C sharp in Arabic.pdf

78

interface Quadrilatére { int Longueur { get; set; } int Largeur{get;set;} float Surface(); } class Rectangle:Quadrilatére { private int Longueur; private int Largeur; public Rectangle(int longueur, int largeur) { this.Longueur = longueur; this.Largeur = largeur; } int Quadrilatére.Longueur { get { return Longueur; } set { Longueur = value;} } int Quadrilatére.Largeur { get { return Largeur; } set { Largeur = value;} } float Quadrilatére.Surface() { return Longueur * Largeur; } }

Rectangle

!!

Page 79: Easy C sharp in Arabic.pdf

79

using System; class Test { static void Main() { Quadrilatére Q = new Rectangle(7, 6); Console.WriteLine(Q.Surface()); Console.ReadKey(); } }

QRectangle

Surface()

Page 80: Easy C sharp in Arabic.pdf

80

Les delegates (delegates)المفوضات .19

execution compilation

Evenementiel

clickdouble click

!

delegate

public delegate string myDelegate(string Texte);

myDelegatestringTexte

system.delegate

myDelegate instance = new myDelegate(Methode_à_passer);

Page 81: Easy C sharp in Arabic.pdf

81

c# 2.0

myDelegate instance = Methode_à_passer;

myDelegateMethode_à_passer

testStringstatic

class testString { public static string isSmall(string Texte) { if (Texte == Texte.ToUpper()) return "Le texte est majiscule"; if (Texte == Texte.ToLower()) return "Le texte est miniscule"; return "Le texte est mélangé"; } public string Longueur(string Texte) { return string.Format("Le longueur de votre texte est : {0}", Texte.Length); } }

Page 82: Easy C sharp in Arabic.pdf

82

public delegate string myDelegate(string Texte);

using System; static void Main() { testString testing = new testString(); string Texte; myDelegate firstDelegate = new myDelegate(testString.isSmall); myDelegate secondDelegate = new myDelegate(testing.Longueur); Console.Write("Entrer votre texte :"); Texte = Console.ReadLine(); Console.WriteLine(firstDelegate(Texte)); Console.WriteLine(secondDelegate(Texte)); Console.ReadKey(); }

isSmall

Page 83: Easy C sharp in Arabic.pdf

83 class Delegates { public delegate string myDelegate(string Texte); class testString { public static string isSmall(string Texte) { if (Texte == Texte.ToUpper()) return "Le texte est majiscule"; if (Texte == Texte.ToLower()) return "Le texte est miniscule"; return "Le texte est mélangé"; } public string Longueur(string Texte) { return string.Format("Le longueur de votre texte est : {0}", Texte.Length); } } static void Main() { testString testing = new testString(); string Texte; myDelegate firstDelegate = new myDelegate(testString.isSmall); myDelegate secondDelegate = new myDelegate(testing.Longueur); Console.Write("Entrer votre texte :"); Texte = Console.ReadLine(); Console.WriteLine(firstDelegate(Texte)); Console.WriteLine(secondDelegate(Texte)); Console.ReadKey(); } }

Page 84: Easy C sharp in Arabic.pdf

84

délégués multicast (multicast)التفویض المتعدد .20

click

sinuscosinus

Math

sinuscosinus

class MultiCast { public static void Sinus(int Number) { Console.WriteLine("Le sinus de ce nombre est :" + Math.Sin(Number)); } public static void Cosinus(int Number) { Console.WriteLine("Le cosinus ce nombre est :" + Math.Cos(Number)); } }

Page 85: Easy C sharp in Arabic.pdf

85

Math

!!!

public delegate void MyDel(int Number); static void Main() { MyDel D1 = MultiCast.Sinus; MyDel D2=MultiCast.Cosinus; MyDel MultiCastDelegate = D1 + D2; Console.WriteLine("L\'appel de chaque methode:\n"); D1.Invoke(60); D2.Invoke(60); Console.WriteLine("Et maintenant les deux appels en seule fois:\n"); MultiCastDelegate(60); Console.ReadKey(); }

Invoke

Page 86: Easy C sharp in Arabic.pdf

86

Les événements (events)األحداث .21

event

delegate

event

handler

ArticleQuantite

Property

class Article { //Attribut private int Quantite; //Constructeur public Article(int quantite) { this.Quantite = quantite; } //Propriété public int QuantiteProperty { get { return Quantite; } set { Quantite = value; } } }

Page 87: Easy C sharp in Arabic.pdf

87

public int Commande(int NbrArticle) { this.Quantite = Quantite - NbrArticle; }

using System; static void Main() { Article article = new Article(20); article.Commande(60); Console.Write(article.QuantiteProperty); Console.ReadKey(); }

2060

40

commandeDelegate

public delegate void commandDelegate();

Page 88: Easy C sharp in Arabic.pdf

88

public event commandDelegate commandEvent;

commande

public void Commande(int NbrArticle) { if (NbrArticle > this.Quantite) commandEvent(); this.Quantite = Quantite - NbrArticle; }

public void messagaEvent() { Console.Write("Rupture de stock !!!!"); }

article.commandEvent += new commandDelegate(article.messagaEvent);

articlecommandDelegate

messageEvent

Page 89: Easy C sharp in Arabic.pdf

89

Article

class Event { class Article { //Evenement **** Event public event commandDelegate commandEvent; //Attribut **** Attribut private int Quantite ; //Constructeur ***** Constructor public Article(int Quantite ) { this.Quantite = Quantite ; } //Propriété ****** Property public int QuantiteProperty { get { return Quantite ; } set { Quantite = value; } } //Méthodes **** Methods public void Commande(int NbrArticle) { if (NbrArticle > this.Quantite) commandEvent(); this.Quantite = Quantite - NbrArticle; } public void messagaEvent() { Console.Write("Rupture de stock !!!!"); } }

Page 90: Easy C sharp in Arabic.pdf

90

public delegate void commandDelegate(); static void Main() { Article article = new Article(20); article.commandEvent += new commandDelegate(article.messagaEvent); article.Commande(60); Console.Write(article.QuantiteProperty); Console.ReadKey(); } }

Page 91: Easy C sharp in Arabic.pdf

91

Les méthodes anonymesاإلجراءات المجھولة .22(Anonymous methods) c# 2.0

Absence

class Absence { int Hours; public int getHours { get { return Hours; } set { Hours = value; } } public Absence(int hours) { this.Hours=hours; } public void verifyAbsence(int MaxHours) { if (getHours > MaxHours) Program.onExceed(); } public static void alertEvent() { Console.WriteLine("Avertissement !!"); } }

AbsenceHours

verifyAbsence

getHourshours

onExceed

Page 92: Easy C sharp in Arabic.pdf

92

public delegate void myDelegate(); static event myDelegate onExceed; static void Main(string[] args) { onExceed += new myDelegate(Absence.alertEvent); Absence absence = new Absence(10); absence.verifyAbsence(8); Console.Read(); } }

onExceed

alertEventstatic

Absence10

verifyAbsence8

alertEvent

verifyAbsence

Page 93: Easy C sharp in Arabic.pdf

93

class Absence { int Hours; public int getHours { get { return Hours; } set { Hours = value; } } public Absence(int hours) { this.Hours=hours; } public void verifyAbsence(int MaxHours) { if (getHours > MaxHours) Program.onExceed(); } }

alertEvent

public delegate void myDelegate(); static event myDelegate onExceed; static void Main(string[] args) { onExceed += delegate() { Console.WriteLine("Avertissement !!"); }; Absence absence = new Absence(10); absence.verifyAbsence(8); Console.Read(); }

delegate

Page 94: Easy C sharp in Arabic.pdf

94

class Program { class Absence { int Hours; public int getHours { get { return Hours; } set { Hours = value; } } public Absence(int hours) { this.Hours=hours; } public void verifyAbsence(int MaxHours) { if (getHours > MaxHours) Program.onExceed(); } } public delegate void myDelegate(); static event myDelegate onExceed; static void Main(string[] args) { onExceed += delegate() { Console.WriteLine("Avertissement !!"); }; Absence absence = new Absence(10); absence.verifyAbsence(8); Console.Read(); } }

Page 95: Easy C sharp in Arabic.pdf

95

Les expressions lambda(lambdaالعبارات المدا .23expressions)

C# 3.0

=> Parameter

(Parameter) => Instruction;

ParameterInstruction

public delegate void myDelegate(); static event myDelegate onExceed; static void Main(string[] args) { onExceed = () => Console.WriteLine("Avertissement"); Absence absence = new Absence(10); absence.verifyAbsence(8); Console.Read(); }

Page 96: Easy C sharp in Arabic.pdf

96

List<>

class Lambda { static void Main(string[] args) { List<String> Alkholafaa = new List<string> { "Abu bakr", "Omar", "Ali", "Othman" }; Console.WriteLine("Alkholafaa arrachidoun are :\n"); Alkholafaa.ForEach(Item => { Console.WriteLine("\t-" + Item); }); Console.Read(); } }

ForEachforeach

Page 98: Easy C sharp in Arabic.pdf

98

Des livres anglais :

o Essential Csharp 3 For dot NET Framework 3 5

o DotNet 3.5 Pro C# 2008 and the .Net 3.5 Platform o CSharp Module 12 Operators Delegates and Events o Programming CSharp, 4th Edition o Pro Csharp with NET3[1].0 Special Edition Apress o Manual Visual CSharp 3.0 And Visual Studio 2005

Des livres français :

o APPRENTISSAGE DU LANGAGE C# 2008 et du Framework .NET 3.5

o Csharp - L'essentiel en concentré(dotnet france) o CSharp Language Specification o Notions avancées du langage Csharp(dotnet france) o Notions fondamentales du langage Csharp(dotnet

france)

Des livres arabes :

o

o 2008

o

Des sites web :

o http://msdn.microsoft.com o http://www.vb4arab.com o http://www.fabienrenaud.com

Page 99: Easy C sharp in Arabic.pdf

99

اجعلهاللهم

عمال خالصا

لوجهك

Page 100: Easy C sharp in Arabic.pdf

100

� �