4 C
Transcript of 4 C
![Page 1: 4 C](https://reader036.fdocumentos.com/reader036/viewer/2022062319/5562cd2ed8b42a63498b46e3/html5/thumbnails/1.jpg)
C#
Msc Luiz Barboza
![Page 2: 4 C](https://reader036.fdocumentos.com/reader036/viewer/2022062319/5562cd2ed8b42a63498b46e3/html5/thumbnails/2.jpg)
Coleções
![Page 3: 4 C](https://reader036.fdocumentos.com/reader036/viewer/2022062319/5562cd2ed8b42a63498b46e3/html5/thumbnails/3.jpg)
Enumerações
![Page 4: 4 C](https://reader036.fdocumentos.com/reader036/viewer/2022062319/5562cd2ed8b42a63498b46e3/html5/thumbnails/4.jpg)
Lis
t -
Gen
eric
s -
Co
mp
arab
le
![Page 5: 4 C](https://reader036.fdocumentos.com/reader036/viewer/2022062319/5562cd2ed8b42a63498b46e3/html5/thumbnails/5.jpg)
Dicionário
![Page 6: 4 C](https://reader036.fdocumentos.com/reader036/viewer/2022062319/5562cd2ed8b42a63498b46e3/html5/thumbnails/6.jpg)
Fila
e P
ilha
![Page 7: 4 C](https://reader036.fdocumentos.com/reader036/viewer/2022062319/5562cd2ed8b42a63498b46e3/html5/thumbnails/7.jpg)
Exceções
![Page 8: 4 C](https://reader036.fdocumentos.com/reader036/viewer/2022062319/5562cd2ed8b42a63498b46e3/html5/thumbnails/8.jpg)
Exceções class TamanhoDeBoloNaoDisponivelException : Exception { public int TamanhoBolo { get; set; } public TamanhoDeBoloNaoDisponivelException(int tam) { TamanhoBolo = tam; } } static void Main(string[] args) { try { EscritaEmBolo bolo = new EscritaEmBolo(8, "alo mamae!"); Console.WriteLine("> " + bolo.textoBolo); } catch (TamanhoDeBoloNaoDisponivelException tbnde) { Console.WriteLine("Desculpe, mas nao trabalhamos como bolos de "
+ tbnde.TamanhoBolo + " cm (apenas 8 ou 16 cm) "); }catch (TextoNaoCompativelComTamanhoBoloException tnctbe){
Console.WriteLine("Desculpe, mas nao é possivel escrever '" } finally { Console.ReadKey(); } }
![Page 9: 4 C](https://reader036.fdocumentos.com/reader036/viewer/2022062319/5562cd2ed8b42a63498b46e3/html5/thumbnails/9.jpg)
Delegates, Expressões Lambae Eventos
![Page 10: 4 C](https://reader036.fdocumentos.com/reader036/viewer/2022062319/5562cd2ed8b42a63498b46e3/html5/thumbnails/10.jpg)
Delegates e Expressões Lamba
public delegate int operacao(int i, int j); class Matematica { public int executaOperacao(operacao oper, int a, int b) { return oper(a, b); } public int soma(int x, int y) { return x + y; } static void Main(string[] args) { int z = 2; int w = 3; Matematica mat = new Matematica(); operacao operSoma = new operacao(mat.soma); int resSoma = mat.executaOperacao(operSoma, z, w); //operacao operSub = new operacao(mat.subtracao); int resSub = mat.executaOperacao((int a, int b) => { return a - b; }, z, w); operacao operDiv = new operacao(mat.divisao); int resDiv = mat.executaOperacao(operDiv, z, w); operacao operMult = new operacao(mat.multiplicacao); int resMult = mat.executaOperacao(operMult, z, w); Console.WriteLine("(+): " + resSoma + " (-): " + resSub
+ " (/): " + resDiv + " (*): " + resMult); Console.ReadLine(); } }
![Page 11: 4 C](https://reader036.fdocumentos.com/reader036/viewer/2022062319/5562cd2ed8b42a63498b46e3/html5/thumbnails/11.jpg)
Eventos
![Page 12: 4 C](https://reader036.fdocumentos.com/reader036/viewer/2022062319/5562cd2ed8b42a63498b46e3/html5/thumbnails/12.jpg)
Eventos
public partial class Form2 : Form { public Form2() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { MessageBox.Show("ALO"); } partial class Form2 { private void InitializeComponent() { this.button1.Click += new System.EventHandler(this.button1_Click); } private System.Windows.Forms.Button button1; }
![Page 13: 4 C](https://reader036.fdocumentos.com/reader036/viewer/2022062319/5562cd2ed8b42a63498b46e3/html5/thumbnails/13.jpg)
C#
Msc Luiz Barboza