Dab tsi yog tub nkeeg instantiation hauv C #?
Dab tsi yog tub nkeeg instantiation hauv C #?

Video: Dab tsi yog tub nkeeg instantiation hauv C #?

Video: Dab tsi yog tub nkeeg instantiation hauv C #?
Video: Pog Ntsum nkauj laug tub nkeeg (qub dab neeg xwb) 8/27/2023 2024, Hlis ntuj nqeg
Anonim

Lazy pib yog ib txoj kev uas defers lub creation ntawm ib yam khoom mus txog rau thaum thawj zaug nws yuav tsum tau. Hauv lwm lo lus, pib ntawm cov khoom tshwm sim tsuas yog ntawm kev thov.

Tsuas yog li ntawd, dab tsi yog tub nkeeg khi hauv C #?

Object on Demand kuj hu ua Lazy loading qauv, Lazy loading ncua kev pib ntawm cov khoom. Qhov no yog ib tug tshiab feature ntawm C# 4.0 thiab tuaj yeem siv tau thaum peb ua haujlwm nrog cov khoom loj thaum nws tsis siv. Txhawm rau zam qhov xwm txheej koj tuaj yeem siv lub Lazy Loading Qauv.

Ib sab saum toj no, thaum twg koj yuav tsum siv Lazy T hom? 7 Teb. Koj feem ntau siv nws thaum koj xav rau instantiate ib yam dab tsi thawj zaug nws ua tau siv . Qhov no ncua tus nqi ntawm kev tsim nws txog thaum / thaum nws xav tau es tsis txhob ua rau tus nqi ib txwm muaj. Feem ntau qhov no yog qhov zoo dua thaum qhov khoom yuav lossis tsis yog siv thiab tus nqi ntawm kev tsim nws yog qhov tsis tseem ceeb.

Tom qab ntawd, ib tug kuj yuav nug, vim li cas tub nkeeg pib?

Lazy pib ntawm ib yam khoom txhais tau hais tias nws cov creation yog ncua mus txog rau thaum nws yog thawj zaug siv. (Rau lub ncauj lus no, cov ntsiab lus tub nkeeg pib thiab tub nkeeg instantiation yog synonymous.) Lazy pib feem ntau yog siv los txhim kho kev ua tau zoo, zam kev suav tsis zoo, thiab txo cov kev xav tau ntawm kev nco.

Dab tsi yog System tub nkeeg?

Lus hais. Siv tub nkeeg kev pib ua kom ncua kev tsim cov khoom loj lossis cov khoom siv siv zog, lossis kev ua haujlwm ntawm kev siv peev txheej, tshwj xeeb tshaj yog thaum tsim lossis ua tiav yuav tsis tshwm sim thaum lub neej ntawm qhov program. Npaj rau tub nkeeg pib, koj tsim ib qho piv txwv ntawm Tub nkeeg.

Pom zoo: