10226

Embed Size (px)

Citation preview

  • 7/31/2019 10226

    1/6

    http://go.microsoft.com/fwlink/?LinkId=192891-regrasdeconvencaodenome

    typesfety--valoressaosempredotipoapropriado

    builtinshort16byte8int324long648float324decimal12816double648bool8stringObjectchar162

    examplesdecalreingvariablestringi;stringi,j;sringi=newstring();

    assignvaluestring="5";

    inti=4;

    c#doesnotallowtouseunassignedvariable--

    implicittypedvariableconceitosdeaplicadoDynamics

    vara=4;(internamenteoC#definedeacordocomovalordefinido)

    variablescope

    foursituations

    procedurescopevoidteste{inta=5...}blockscopeif(a==5){intb=6..}classscopeclassCar{privateintqtde;}namespacescopenamespaceT{classT{..}classX{..}}

    convertavaluediferentDataTypeimplicityconversion-AutomaticallyperfomedCLRwithoutlosinginformationexplicitconversion-requiresyouwritetocodetoperformaconversioncanbe

    loseinformationorproduceanerror

    sbyte-short,int,long,float,double,dercimalbyte-short,int,long,float,double,dercimal,ushort,uint,ulongshort-int->ushort-inte..eosuint,ulongint->longe...unit->longe..eoulongfloat->doublelong,ulong->float,double,decimal

  • 7/31/2019 10226

    2/6

    char->menosobyte(chartemdezesseisbytes)

    conversionquetemalgumarelacaointerface,heranca,tipomaiorpramenor(longint)

    useinta=(int)long1;roundbrackets()naoseiporqueparenthesis

    anothertypeofconvertionusingSystem.Convert1-Convert.ToInt32("444");

    2-inti;if(int.TryParse("5436",outi))-themethodassignedthetypeiwhenconditionistrue.

    readonly-constants

    examplesreadonlystringcurrentDate;or

    readonlystringcurrentDate=DateTime.Now.ToString();

    constdoublePI=3.1415(jasaberovalor)

    readonlycanbedeclaringeinitializinafterinconstructorclasscontonlyinitializedwhenitisdeclared.

    usingexpressionsoperandarevaluesOperatoesdefineoperationtoperformonoperands

    becarefullbecausethereisaconversionthatoccuredfirst1+5.05/2returnonlyinteger5.0/2convert2todouble

    arithmeticincrementcomparisonstringlogical&|^!~&&casting()assigment=,+,+tyoeinformationsizeoftypeofdelegateconcatenationoverflowchecked,uncheckedindirectionconditional?:TERNARY

    answer=answer+1;BINARYanswer++;UNARY

    answer=answer+42;answer+=42;

    orderprecedenceprefixes++,--,+,-(UNARY)-6,+5,!,~

  • 7/31/2019 10226

    3/6

    *,/,%+,-,>=

  • 7/31/2019 10226

    4/6

  • 7/31/2019 10226

    5/6

    case2:default:

    }

    havecommandsgoto0:andreturn:case50:Console.WriteLine("valorMaiorque50");gotocase30;case40:Console.WriteLine("valorMaiorque40");break;case30:

    useaswitchstatementtoperformanactionbasedonthepossiblevaluesofasinglevariable

    if/elseif/else->involveseveralvariablesif->involveseveralvariables

    UsingITeraionStatements

    WHILE-enablesexecute0ormoretimesdo-enablesexecuteoneormoretimesfor-enablesrepetedlyasetnumberoftimes

    while(a==5){

    }

    do{

    }while(a==5)

    for([countervariable]=[startingvalue];[limit];[countermodification]){

    }

    i++i+=2i--

    201pareibreakandcontineu

  • 7/31/2019 10226

    6/6