Sunday 23 July 2017

Lecture#3 ka Point#81 (Csharp Roman Hindi/Urdu Me).

Constructor(Basic member of class):

Constructors is a special type of functions. Constructor class k tamam functions me sab se top pe likha jaye hai. Constructor ka naam aur class ka naam same hona chahiye. Constructor ki return data type nahi hoti matlab yeh k constructor kuch bhi return nahi kre ga to is liye constructor k saath na to hum koi return data type likhtey hain aur na hi void ka keyword likhtey hain. Sirf constructor k saath us ka access modifier likhtey hain.



Constructor ki aik khaas property yeh bhi hai k jab hum constructor nahi bnatey to aik default constructor program me tab bhi mojood hota hai. Yeh kesey pata chaley ga k is program ki class ka default constructor hai? Woh is tarha k jab aap class ka object bna rhey hongey to new k keyword k baad jo aap ne class ka naam likha hoga us pe mouse hover kre to .NET Framework intellisense aap ko bta de ga k className.constructor(). Class ka object bnatey waqt constructor sirf aik dafa call hoga. Constructor ka kaam hota hai to initialize. Agar hum apna constructor bnaye ge to humara bnaya hua constructor hi call hoga jab k default constructor call nahi hoga.



Memory me jab aap koi object initialize kr rhey hotey hain to operating system se humara constructor request krta hai k is object ko memory allocate ki jaye ya memory me jaga di jaye. Constructor on the behalf of CLR, operating system se request krta hai k merey object ko memory allocate ki jaye(jitney us class k members space occupy kre ge utney size ki memory allocate hogi).

No comments:

Post a Comment