1 / 36

Ministrantes: Giane Binotto Guilherme Cassales Leonardo Quatrin Liza Lunardi Luiz Schirmer

Minicurso de C#. Ministrantes: Giane Binotto Guilherme Cassales Leonardo Quatrin Liza Lunardi Luiz Schirmer Pablo Bizzi Tiago Engel. A Linguagem. É uma linguagem de programaação da Plataforma .NET, derivada de C/C++ orientada à objetos.

adah
Download Presentation

Ministrantes: Giane Binotto Guilherme Cassales Leonardo Quatrin Liza Lunardi Luiz Schirmer

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Minicurso de C# Ministrantes: GianeBinotto Guilherme Cassales Leonardo Quatrin Liza Lunardi Luiz Schirmer Pablo Bizzi Tiago Engel .

  2. A Linguagem É uma linguagem de programaação da Plataforma .NET, derivada de C/C++ orientada à objetos. É a linguagem nativa para .NET CommonLanguageRuntime(CLR) Uma classe base pode ser escrita em C#, derivada em Visual Basic e novamente derivada em C#.

  3. Características • Simples • Programação Orientada a Objetos • Muito semelhante ao JAVA • Tipagem forte

  4. C# vs JAVA • Unsigned Integers • Complex Numbers

  5. Iniciando novo projeto • File New Project • Visual C# Console Application OK using System; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { } } }

  6. Hello World! Console.WriteLine("HelloWorld");

  7. Tipos: object: compatível com todos os tipos e todas as operações de object types são compatíveis com os tipos citados acima.

  8. Simple Types

  9. Operadores

  10. Visibilidade das Variáveis • Private: Significa que, exceto a classe incluída, nada pode acessar o objeto, método ou variável; • Public: Significa que todos têm acesso livre a este membro; • Protected: Significa que são apenas visíveis para as classes derivadas por meio de herança; • Internal: todos têm acesso livre a este membro dentro de um assembly (DLL ou EXE; correspondente ao JAR do Java). Fora do assembly a classe é inacessível.

  11. COLOCAR EXEMPLOS DE USO DE FLOATS, CHARS E AFINS

  12. Enums • Lista contendo constantes enum Color { red, blue, green }

  13. Color mColor; mColor = Color.red; //mColor = Color.green; //mColor = Color.blue; if (mColor == Color.blue) { Console.WriteLine("blue"); } else if (mColor == Color.green) { Console.WriteLine("green"); } else if (mColor == Color.red) { Console.WriteLine("red"); }

  14. Arrays • Guardar uma quantidade de valores de um tipo. • N dimensões. • Uma dimensão: int[] array = new int[5]; int[] array1 = new int[] { 2, 3, 5, 6, 7 }; int[] array2 = { 2, 3, 5, 6, 7 }; Console.WriteLine(array.Length.ToString());

  15. Arrays • Duas dimensões - dois modos: int[][] a = new int[2][]; a[0] = new int[3]; a[1] = new int[4]; int x = a[0][1]; int len = a[0].Length; // 3 Console.WriteLine(len + " " + a.Length); //3 2

  16. Arrays int[,] a = new int[2, 3]; int x = a[0, 1]; int len = a.Length; // 6 Console.WriteLine(len + " " + a.GetLength(0) + " " + a.GetLength(1)); // 6 2 3 • Interpretações diferentes:

  17. String • Biblioteca System; • Utilizado apenas como "string"; • Imutáveis (StringBuilder); • Concatenadas pelo símbolo '+'; • Acesso por index: s[i]; • Tamanho: Length; • Reference types; • Podem ser usados pra comparação com os operadores == e !=; • Operações: CompareTo, IndexOf, StartsWith, Substring, ...;

  18. If if ('0' <= ch && ch <= '9') val = ch - '0'; else if ('A' <= ch && ch <= 'Z') val = 10 + ch - 'A'; else { val = 0; Console.WriteLine("invalid character {0}", ch); }

  19. Switch switch (country) { case "Germany": case "Austria": case "Switzerland": language = "German"; break; case "England": case "USA": language = "English"; break; case null: Console.WriteLine("no country specified"); break; default: Console.WriteLine("don't know language of {0}", country); break; }

  20. Switch GOTO int state = 0; int ch = Console.Read(); switch (state) { case 0: if (ch == 'a') { ch = Console.Read(); goto case 1; } else if (ch == 'c') goto case 2; else goto default; case 1: if (ch == 'b') { ch = Console.Read(); goto case 1; } else if (ch == 'c') goto case 2; else goto default; case 2: Console.WriteLine("input valid"); break; default: Console.WriteLine("illegal character {0}", ch); break; }

  21. Loops do { sum += a[i]; i--; } while (i > 0); while (i < n) { sum += i; i++; } for (int i = 0; i < n; i++) sum += i;

  22. Loop foreach string s = "Hello"; foreach (char ch in s) Console.WriteLine(ch); int[] a = {3, 17, 4, 8, 2, 29}; foreach (int x in a) sum += x; Queue<string> q = new Queue<string>(); q.Enqueue("John"); q.Enqueue("Alice"); foreach (string s in q) Console.WriteLine(s);

  23. Funções public int Add (int x, int y) { return x+y; } Acessando dentro da classe: int resultado = this.Add(3, 5); Acessando por outra classe: C c = new C(); int resultado = c.Add(3, 6);

  24. Struct | Class Diferenças

  25. Struct | Class

  26. Exemplo de Struct struct Point { public int x, y; public Point (int x, int y) { this.x = x; this.y = y; } public void MoveTo (int a, int b) { x = a; y = b; } }

  27. Exemplo de Class class Rectangle { Point origin; public int width, height; public Rectangle() { origin = new Point(0,0); width = height = 0; } public Rectangle (Point p, int w, int h) { origin = p; width = w; height = h; } public void MoveTo (Point p) { origin = p; } }

  28. Struct | Class public vs private public class Stack { private int[] val; private int top; public Stack() {...} public void Push(int x) {...} public int Pop() {...} } private default

  29. Componentes de uma Classe/Struct class C { fields, constants // for object-oriented programming methods constructors, destructors properties // for component-based programming events indexers // for amenity overloaded operators nested types (classes, interfaces, structs, enums, delegates) ... }

  30. System.Math Sqrt Math.Sqrt(value) Pow Math.Pow(value, power) Cos Math.Cos(angle*Math.PI/180); Sin Math.Sin(radians); Tan Math.Tan(radians); Min Math.Min(xInt1, xInt2) Max Math.Max(xInt1, xInt2)

  31. Exercícios • Faça uma classe calculadora, que possua funções de soma, subtração, raiz quadrada, fatorial, potência. Como será feito em console, crie uma classe com um valor X e o usuário vai digitar a operação (ex: somar) e logo após o programa pede o valor a ser mandado para aplicá-lo ao valor X que a classe possui. (Ex: valor que a classe possui é 5, o usuário digita "subtrair" e o console pede o número, entao o usuário digita 3. Ao final, o programa imprime na tela o valor 2)

  32. WPF - Windows Presentation Form

  33. Tutorial SDK Kinect Desenvolvido por Luiz Jose Schirmer Silva: • http://www-usr.inf.ufsm.br/~luiz/MinicursoKinectSdk.doc

  34. Bibliografia/Material Adicional • http://ssw.jku.at/Teaching/Lectures/CSharp/Tutorial/Part1.pdf • http://ssw.jku.at/Teaching/Lectures/CSharp/Tutorial/Part2.pdf • http://msdn.microsoft.com/en-us/library/aa288436(v=vs.71).aspx • http://www.csharp-station.com/Tutorial.aspx • http://www.etelg.com.br/paginaete/downloads/informatica/apostila.pdf • http://msdn.microsoft.com/en-us/library/system.math.aspx • http://pplware.sapo.pt/tutoriais/tutorial-c-o-que-e-o-wpf-windows-presentation-foundation/

More Related