GetType C# yog dab tsi?
GetType C# yog dab tsi?

Video: GetType C# yog dab tsi?

Video: GetType C# yog dab tsi?
Video: C# type casting 💱 2024, Kaum ib hlis
Anonim

Nkag siab qhov tshwm sim ntawm cov GetType txoj kev. GetType rov qab hom khoom. GetType yog ib txoj kev ntawm cov khoom. Nws muab ib hom khoom, ib qho uas qhia tau hais tias feem ntau derived hom ntawm cov khoom piv txwv. Qhov kev pab cuam no pab peb nkag siab txog cov chav kawm hauv paus thiab muab cov chav kawm sib raug zoo. TypeObject.

Tsis tas li ntawd, dab tsi yog siv hom ntawm C #?

Cov hom ntawv yog tus neeg teb xov tooj lo lus tseem ceeb uas yog siv kom tau ib hom ntawm lub sij hawm compile. Los yog ua lwm yam lus, tus neeg teb xov tooj no yog siv kom tau qhov System. Hom khoom rau ib hom. Tus neeg teb xov tooj no siv hom nws tus kheej ua kev sib cav thiab xa rov qab hom cim ntawm qhov kev sib cav.

Ib tug kuj yuav nug, koj yuav ua li cas xyuas seb qhov khoom puas yog ib qho piv txwv ntawm chav kawm C#? Tus neeg teb xov tooj yog siv los ua kuaj yog tias lub sijhawm ua haujlwm ntawm ib qho khoom yog sib xws nrog hom muab los yog tsis. Nws rov qab muaj tseeb yog cov muab khoom yog ntawm tib hom txwv tsis pub, rov qab tsis tseeb. Nws kuj rov qab tsis tseeb rau null khoom . Ntawm no, cov lus qhia yuav raug ntsuas rau ib qho piv txwv ntawm qee hom.

Tom qab ntawd, ib tus tuaj yeem nug, qhov txawv ntawm GetType thiab hom hauv C # yog dab tsi?

hom ntawv lo lus tseem ceeb yuav siv hom nws tus kheej raws li kev sib cav thiab rov qab cov kab hauv qab Hom kev sib cav whereas GetType () tsuas tuaj yeem hu rau ntawm qhov piv txwv ntawm hom. Employee neeg ua hauj lwm = new Employee(); Qhov system.

Koj pom hom khoom li cas?

Java muab peb txoj kev sib txawv los nrhiav cov hom ntawm khoom hauv runtime e.g. piv txwv ntawm lo lus tseem ceeb, getClass() thiab isInstance() txoj kev ntawm java. lang. Chav kawm . Tawm ntawm tag nrho peb tsuas yog getClass() yog qhov uas pom tseeb Hom ntawm khoom hos lwm tus kuj rov qab muaj tseeb yog tias Hom ntawm khoom yog tus super hom.

Pom zoo: