Cov txheej txheem:

Dab tsi yog qhov xwm txheej hauv C#?
Dab tsi yog qhov xwm txheej hauv C#?

Video: Dab tsi yog qhov xwm txheej hauv C#?

Video: Dab tsi yog qhov xwm txheej hauv C#?
Video: Dab ntxwg nyoos yog leej twg ...zaj no zoo heev. 2024, Kaum ib hlis
Anonim

Cov khoom uas tsa lub xwm txheej yog hu ua xwm txheej tus xa. Cov xwm txheej sender tsis paub yam khoom los yog txoj kev yuav tau txais (kawg) lub xwm txheej nws nce. Kom txhais ib xwm txheej , koj siv C# xwm txheej los yog Visual Basic Kev tshwm sim lo lus tseem ceeb hauv kos npe ntawm koj xwm txheej chav kawm, thiab qhia meej hom delegate rau lub xwm txheej.

Ntxiv mus, dab tsi yog qhov xwm txheej hauv C# nrog piv txwv?

C# - Cov xwm txheej . Cov xwm txheej yog cov neeg siv kev ua xws li cov xovxwm tseem ceeb, nyem, nas txav, thiab lwm yam, lossis qee qhov tshwm sim xws li cov ntawv ceeb toom tsim tawm. Cov ntawv thov yuav tsum teb rau xwm txheej thaum lawv tshwm sim. Rau piv txwv , cuam tshuam.

Ib yam li ntawd, siv cov xwm txheej hauv C# yog dab tsi? Hauv c# , xwm txheej yog siv los ua kom muaj chav kawm lossis cov khoom kom ceeb toom rau lwm cov chav kawm lossis cov khoom ntawm qhov kev txiav txim uas yuav tshwm sim. Tshaj tawm ib xwm txheej , peb yuav tsum siv qhov xwm txheej lo lus tseem ceeb nrog delegate hom. Ua ntej raising ib xwm txheej , peb yuav tsum tau xyuas seb ib tug xwm txheej yog subscribed los tsis tau.

Hais txog qhov no, dab tsi yog qhov kev tshwm sim handler hauv C #?

Event handlers yog cov txheej txheem nyob rau hauv ib yam khoom uas raug tua nyob rau hauv teb rau ib co xwm txheej tshwm sim hauv daim ntawv thov. Kom nkag siab qhov xwm txheej tuav qauv ntawm. Net moj khaum, peb yuav tsum to taub lub tswvyim ntawm delegate.

Yuav ua li cas kuv hu 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.

Pom zoo: