Cov txheej txheem:

Cov xwm txheej puas muaj rov qab hom C#?
Cov xwm txheej puas muaj rov qab hom C#?

Video: Cov xwm txheej puas muaj rov qab hom C#?

Video: Cov xwm txheej puas muaj rov qab hom C#?
Video: Saib Mis paub Poj niam (hluas nkauj) tus yam ntxwv lub siab 2024, Plaub Hlis Ntuj
Anonim

Ua cov txheej xwm muaj hom rov qab los

Raws li feem ntau xwm txheej tus tuav rov qab los void, vim single xwm txheej muaj muaj ob peb subscribers, thiab rov qab tus nqi tuaj yeem ua tsis meej. Txawm li cas los xij, nws tuaj yeem ua tau rau cov neeg ua haujlwm rov qab los tus nqi. Nws nyob ntawm qhov hom ntawm tus delegate koj tshaj tawm xwm txheej nrog.

Ib yam li ib tug yuav nug, cov xwm txheej puas muaj rov qab hom C#?

Feem ntau koj yuav tso " rov qab los values" nyob rau hauv cov khoom EventArgs, yog vim li cas xwm txheej tsis txhob xav tau rau rov qab los muaj nuj nqis tab sis lawv tuaj yeem yog lawv tau hais rau. Raws li feem ntau xwm txheej tus tuav rov qab los void, txawm li cas los xij, nws muaj peev xwm ua tau rau cov neeg ua haujlwm rov qab los tus nqi.

Tsis tas li ntawd, cov neeg tuav haujlwm ua haujlwm li cas C#? Cov xwm txheej feem ntau yog siv los teeb liab cov neeg siv kev ua xws li khawm clicks lossis xaiv cov ntawv qhia zaub mov hauv graphical user interfaces. Thaum ib xwm txheej muaj ntau tus subscribers, cov cov neeg tuav kev tshwm sim yog invoked synchronously thaum ib xwm txheej yog tsa. Hu rau xwm txheej asynchronously, saib Hu Synchronous Methods Asynchronously.

Tsis tas li ntawd, kuv yuav ua li cas thiaj hu tau ib qho kev tshwm sim hauv C#?

Cov ntsiab lus tseem ceeb:

  1. Siv cov ntsiab lus tseem ceeb nrog rau hom delegate tshaj tawm ib qho kev tshwm sim.
  2. Txheeb xyuas qhov xwm txheej yog null lossis tsis ua ntej tsa qhov xwm txheej.
  3. Sau npe rau cov xwm txheej siv "+=" tus neeg teb xov tooj.
  4. Function uas tuav qhov xwm txheej yog hu ua event handler.
  5. Cov xwm txheej tuaj yeem muaj kev sib cav uas yuav dhau mus rau tus neeg ua haujlwm.

Cov xwm txheej puas tuaj yeem muaj kev hloov kho?

Txheej xwm tuaj yeem raug cim raws li pej xeem, ntiag tug, tiv thaiv, sab hauv, tiv thaiv sab hauv, lossis ntiag tug tiv thaiv. Cov no nkag mus modifiers txhais li cas cov neeg siv ntawm chav kawm nkag tau tus xwm txheej.

Pom zoo: