Txoj kev GetType ntawm qhov khoom xa rov qab yog dab tsi?
Txoj kev GetType ntawm qhov khoom xa rov qab yog dab tsi?

Video: Txoj kev GetType ntawm qhov khoom xa rov qab yog dab tsi?

Video: Txoj kev GetType ntawm qhov khoom xa rov qab yog dab tsi?
Video: Kawm Lus Askiv Page 69 -- Expressions 2024, Kaum ib hlis
Anonim

Yam khoom yog lub hauv paus chav kawm rau txhua hom hauv. NET type system, cov Txoj kev GetType siv tau rau rov qab los Hom khoom uas sawv cev rau txhua tus. Yam khoom , Tus nqi hom, uas yog muab los ntawm System.

Ua kom pom qhov no, koj yuav nrhiav tau 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.

Tsis tas li ntawd, GetType C# yog dab tsi? 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.

Kuj Paub, ua li cas koj thiaj li tau txais hom khoom los ntawm cov rooj sib txoos uas twb tau thauj khoom lawm?

Siv Hom . GetType kom tau Hom khoom los ntawm ib kev sib dhos uas yog xa loaded.

Qhov txawv ntawm Typeof thiab GetType 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.

Pom zoo: