You are on page 1of 6

http://go.microsoft.com/fwlink/?

LinkId=192891 -regras de convencao de nome type sfety -valores sao sempre do tipo apropriado built in short 16 byte 8 int 32 long 64 float 32 decimal 128 double 64 bool 8 string Object char 16

4 8 4 16 8 2

examples decalreing variable string i; string i,j; sring i = new string(); assign value string = "5"; int i = 4; c# does not allow to use unassigned variable -implicit typed variable conceitos de aplicado Dynamics var a = 4; (internamente o C# define de acordo com o valor definido)

variable scope four situations procedure scope void teste { int a = 5... } block scope if(a==5){ int b =6..} class scope class Car{ private int qtde; } namespace scope namespace T{ class T{..} class X{..}} convert a value diferent Data Type implicity conversion - Automatically perfomed CLR without losing information explicit conversion - requires you write to code to perform a conversion can be lose information or produce an error sbyte - short,int,long,float,double,dercimal byte - short,int,long,float,double,dercimal,ushort,uint,ulong short - int -> ushort - int e ..e os uint,ulong int -> long e ... unit ->long e .. e o ulong float -> double long,ulong -> float,double,decimal

char -> menos o byte (char tem dezesseis bytes) conversion que tem alguma relacao interface,heranca, tipo maior pra menor(long int) use int a = (int) long1; round brackets () nao sei porque parenthesis another type of convertion using System.Convert 1 - Convert.ToInt32("444"); 2 int i; if (int.TryParse("5436", out i)) - the method assigned the type i when condition is true. readonly - constants examples readonly string currentDate; or readonly string currentDate = DateTime.Now.ToString(); const double PI = 3.1415 (ja saber o valor) readonly can be declaring e initializin after in constructor class cont only initialized when it is declared. using expressions operand are values Operatoes define operation to perform on operands be carefull because there is a conversion that occured first 1 + 5.0 5 /2 return only integer 5.0 /2 convert 2 to double arithmetic increment comparison string logical & | ^! ~ && casting () assigment =,+,+ tyoe information sizeof typeof delegate concatenation overflow checked,unchecked indirection conditional ?: TERNARY answer = answer + 1; BINARY answer++; UNARY answer = answer + 42; answer += 42; order precedence prefixes ++,--, +,- (UNARY) -6 , +5, !,~

*,/,% +,<<,>> <,>,>=<<= ==,!= & ^ | && mesma precedencia left to right an ao ser a = b a = b =c todos recebem o valor de C... strting immutable = new string are created.. is better to use StringBuilder() System.Text; Creating and using Arrays ---> arrays enable you to read and process a variable number of related data items set of objects area grouped togheter and managed as unit every element in the array contais a vale arrats are zero-indexed the length total number it can contain the lower bound, is index of its firt element can be single dimension,multidimension, or jagged rankl is number of dimensions in the array initializing array int[] arr1 = new int[3]; int[,] arr2 = new int [2,2] size1 e size2 - multidimensional int [][] arr3 = new int[2][]; arrayJagged if not initializing array C# initialize for you int = zeros string = null int[] arr4 = new int{1,2,3,4,5}; specify 32 dimensios --max --int[,] arr1 = new int[2,2]; int[,] arr2 = {{1,2},{3,4},} [0,0] [0,1] [1,1] [1,2] = = = = 1 2 3 4

jagged array 0-- arrary of array size of each array can vary int [][] arr3 = new int[2][]; arrayJagged arr3[0] = new int[2]; arr3[1] = new int[3]; implicitly typed arrays var numbers = new[]{1,2,3,4}; Common methods --: Length() Rank() CopyTo() Sort() --BinarySearch Array.BinarySearch reseachr a term in Array single-dimensional clone --shallow copies elements in array not does not copy objects; getEnumerator getLength(0) length dimension getValue(1) o valor do elemento do indice 1 Rank numbers of dimension LEngth; numbers of item array Sort: Array.Sort using decision statements specify alternatives && - AND || - OR if - statemente recommendation if() { } tips bIndica = (valor>0) && (valor<=0); o mesmo que fazer um if para colocar o valor true nessa variavel. short-circuit --> nao verificar todas as expressoes para determinar --outror conceito o uso do ternario ? : bool bCerto = valori > 0 ? true : false; importante observar o if so atende o primeiro caso que satisfaz a condicao.. --> string,integer,bool switch(a) { case 0: case 1:

case 2: default: } have commands goto 0: and return: case 50: Console.WriteLine("valor Maior que 50"); goto case 30; case 40: Console.WriteLine("valor Maior que 40"); break; case 30: use a switch statement to perform an action based on the possible values of a single variable if/elseif/else -> involve several variables if -> involve several variables Using ITeraion Statements WHILE - enables execute 0 or more times do - enables execute one or more times for - enables repetedly a set number of times while (a==5) { } do { }while(a==5) for([counter variable] = [starting value];[limit];[counter modification]) { } i++ i+= 2 i-201 parei break and contineu

You might also like