More Related Content Similar to Imparare c n.104 Similar to Imparare c n.104 (20) Imparare c n.1041. IMPARARE C# INTRODUZIONE Era l’anno 2001, quando iniziai ad avvicinarmi al .NET Framework. Questa nuova tecnologia era ancora in versione beta con tutto ciò che ne conseguiva. Da allora sono passati cinque anni ed il .NET Framework studiato, realizzato e distribuito dalla Microsoft ha preso ormai piede in diversi ambiti e settori, a dimostrazione che la direzione presa cinque anni fa era probabilmente la più giusta. Nel corso di questi anni, il .NET Framework è cresciuto e maturato fino ad arrivare alla versione 2.0 (o 2005) corredato da svariati tool di sviluppo estremamente potenti e versatili. Indubbiamente, il più potente editor con cui scrivere software in .NET è Microsoft Visual Studio 2005. a cui si affiancano delle versioni più leggere denominate Express. Per scrivere software in CSharp 2005, la versione da scaricare gratuitamente è Microsoft Visual CSharp 2005 Express Edition, scaricabile dal seguente indirizzo: http://msdn.microsoft.com/vstudio/express/visualcsharp/. Scaricalo gratis su http://www.punto-informatico.it/ PILibri 2. IMPARARE C# INDICE Introduzione . . . . . . . . . . . . . . . . . . . . . . . . . …… 7 Elementi del linguaggio 1.1 Il .net framework . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9 1.2 Il linguaggio csharp . . . . . . . . . . . . . . . . . . . . . . . . . . . .13 Hello world 2.1 Fondamenti . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 2.2 I tipi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17 2.3 Variabili e costanti . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 2.4 Operatori ed espressioni . . . . . . . . . . . . . . . . . . . . . . . .26 2.5 Enum . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 2.6 Istruzioni di controllo di flusso . . . . . . . . . . . . . . . . . . . .29 Classi ed oggetti 3.1 Oggetti e classi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .37 3.2 Membri statici . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 3.3 Distruzione degli oggetti . . . . . . . . . . . . . . . . . . . . . . . .48 3.4 Parametri . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 3.5 Overloading dei metodi . . . . . . . . . . . . . . . . . . . . . . . . .51 3.6 Proprietà . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .53 Scaricalo gratis su http://www.punto-informatico.it/ PILibri 3. IMPARARE C# Principi di object oriented programming 4.1 Pensare ad oggetti . . . . . . . . . . . . . . . . . . . . . . . . . . . .57 4.2 Incapsulamento . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 4.3 Ereditarietà . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .60 4.4 Poliformismo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .63 4.5 Astrazione . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .65 4.6 Sealed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .69 4.7 I namespace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .70 4.8 A cosa servono . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .70 4.9 Using . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .71 4.10 Alias . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .71 4.11 Creazione di namespace personalizzati . . . . . . . . . . .72 4.12 Strutture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73 4.13 Definire strutture . . . . . . . . . . . . . . . . . . . . . . . . . . . . .74 4.14 Creare strutture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .74 4.15 Interfacce . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .75 4.16 Definire ed implementare interfacce . . . . . . . . . . . . . .76 4.17 Sovrascrivere i membri dell’interfaccia . . . . . . . . . . . .78 4.18 Implementazione esplicita dell’interfaccia . . . . . . . . . 79 4.19 Poliformismo con le interfacce . . . . . . . . . . . . . . . . . . 81 4.20 Quando usare le interfacce e le classi astratte . . . . . .82 Scaricalo gratis su http://www.punto-informatico.it/ PILibri 4. IMPARARE C# Array indici e collections 5.1 Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .84 5.2 Foreach . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .88 5.3 Indexers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .89 5.4 Le collection incluse in system.collection . . . . . . . . . . .93 5.5 Collection interfaces . . . . . . . . . . . . . . . . . . . . . . . . . .100 5.6 Gestione delle eccezioni . . . . . . . . . . . . . . . . . . . . . . .101 5.7 Sollevare e gestire le eccezioni . . . . . . . . . . . . . . . . . 102 5.8 Gestione di più eccezioni . . . . . . . . . . . . . . . . . . . . . . 104 5.9 Finally . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .107 5.10 Eccezioni personalizzate . . . . . . . . . . . . . . . . . . . . . 109 5.11 Risollevare un’eccezione . . . . . . . . . . . . . . . . . . . . . 110 5.12 Utilizzare correttamente le eccezioni . . . . . . . . . . . . 112 5.13 Delegati ed eventi . . . . . . . . . . . . . . . . . . . . . . . . . . .112 5.14 Delegates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 5.15 Eventi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124 Scaricalo gratis su http://www.punto-informatico.it/ PILibri 5. IMPARARE C# Novità C# 2.0 6.1 Generics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .131 6.2 Tipi composti . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .142 6.3 Collection generiche . . . . . . . . . . . . . . . . . . . . . . . . . .149 6.4 Anonymous methods . . . . . . . . . . . . . . . . . . . . . . . . .152 6.5 Partial types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153 6.6 Iterators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .154 Scaricalo gratis su http://www.punto-informatico.it/ PILibri