• Primeiro C# se pronuncia (C Sharp).
  • Baseada em Java com algumas características de C++.
  • Os tipos de dados do C#.

C# Type

.NET Framework type

bool

System.Boolean

byte

System.Byte

sbyte

System.SByte

char

System.Char

decimal

System.Decimal

double

System.Double

float

System.Single

int

System.Int32

uint

System.UInt32

long

System.Int64

ulong

System.UInt64

object

System.Object

short

System.Int16

ushort

System. UInt16

string

System.String

 

  • Palavras reservadas

 

abstract
as
base
Bool

foreach
goto
if
implicit

in
int
interface
internal

protected
public
readonly
ref 

break
byte
case
Catch

finally
fixed
float
for

new
null
object
operator

return
sbyte
sealed
short

char
checked
class
Const

event
explicit
extern
false

out
override
params
private

struct
switch
this
throw

continue
decimal
default
Delegate

do
double
else
Enum

is
lock
long
namespace

sizeof
stackalloc
static
string

 

  • Tipos de variáveis:

C# Type

Valores possíveis de se armazenar

bool

Verdadeiro ou Falso (Valores booleandos)

byte

0 a 255 (8 bits)

sbyte

-128 a 127 (8 bits)

char

Um caractere (16 bits)

decimal

±1.0 × 10−28 a ±7.9 × 1028 (128 bits)

double

±5.0 × 10−324 a ±1.7 × 10308 (64 bits)

float

±1.5 × 10−45 a ±3.4 × 1038 (32 bits)

int

-2,147,483,648 a 2,147,483,647 (32 bits)

uint

0 a 4,294,967,295 (32 bits)

long

–9,223,372,036,854,775,808 a 9,223,372,036,854,775,807 (64 bits)

ulong

0 a 18,446,744,073,709,551,615 (64 bits)

object

Qualquer tipo.

short

-32,768 a 32,767 (16 bits)

ushort

0 a 65,535 (16 bits)

string

Seqüência de caracteres (16 bits por caractere)

 

  • Declarando variável : int idade;
  • Declarando e dando um valor inicial: int idade = 18;
  • Declarando mais de uma variável do mesmo tipo: string nome, endereco, telefone;
  •  Declarando mais de uma variável do mesmo tipo e dando valor a só uma delas:String nome, endereço, telefone = “1111-1111”;
  • Variáveis string usam aspas duplas “” já do tipo char aspas simples ‘’: string nome = “Eleutério”;     Char Sexo = ‘M’;   
  • Cuidado , variável Char ( character ) colocar apenas uma letra.
  • Criando um contador : Valor += 5;  Incrementa de 5 em 5, ou o mesmo que escrever Valor = Valor + 5 ;
  • Fechar um Form : Close(); ou ainda this.Close();
  • Abrir um Form: Form2 F2 = new form2();

F2.Show();

  • Estrutura clássica:

1.      Métodos;

2.      Classes;

3.      Interfaces;

4.      Enum;

5.      Delegates;

 

 

Vejamos um exemplo mais complexo.

Somar os valores de dois text e colocar o resultado em um terceiro text.

Crie um Form com 3 text e 1 botão.


Coloque os nomes dos objetos como abaixo:

1.      txt_Valor1

2.      txt_Valor2

3.      txt_Resultado

4.      btn_Somar

Agora vamos ao código

 

No botão somar coloque este código

 

private void btn_Somar_Click(object sender, EventArgs e)
        {
            int Valor1;
            int Valor2;
            int Resultado;



            valor1 = int.Parse(txt_Valor1.Text);
            valor2 = int.Parse(txt_Valor2.Text);
            Result ado = Valor1 + Valor2;

            txt_Resultado.Text = Resultado.ToString();

        }