13
C# Msc Luiz Barboza

4 C

  • Upload
    lcbj

  • View
    295

  • Download
    0

Embed Size (px)

Citation preview

Page 1: 4 C

C#

Msc Luiz Barboza

Page 2: 4 C

Coleções

Page 3: 4 C

Enumerações

Page 4: 4 C

Lis

t -

Gen

eric

s -

Co

mp

arab

le

Page 5: 4 C

Dicionário

Page 6: 4 C

Fila

e P

ilha

Page 7: 4 C

Exceções

Page 8: 4 C

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

Delegates, Expressões Lambae Eventos

Page 10: 4 C

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

Eventos

Page 12: 4 C

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

C#

Msc Luiz Barboza