-----------------------------------------------------------

New Message on BDOTNET

-----------------------------------------------------------
From: shahkalpesh
Message 2 in Discussion

Hi Monica,

Well, its an option that language provides, you could use function to allow/disallow 
access to class members

for eg
class sample
{
        int ctr;
        
        public void setCtr(int value)
        {
                ctr = value;
        }

        public int getCtr()
        {
                return ctr;
        }
}  

of course, you can set any/both of the above function to private to disallow access to 
your member

alternatively, you could write them using property statements
class sample
{
        int ctr;
        
        public int Ctr
        {
                get
                {
                        return ctr;
                }
                set
                {
                        ctr = value;
                }
        }
}  

the user of the class might have to write the code, as below if you are using a 
function based approach
void main(String[] args)
{
        sample s =new sample();
        // if you want to increment value of ctr
        s.setCtr(s.getCtr() + 1);
}


using property based approach,
void main(String[] args)
{
        sample s = new sample();
        s.Ctr++;
}

looking at both the examples, the property seems more natural to read & write, isnt it 
?

I know this is really a simple example, but I hope it gives you a way to look at use 
of properties

HTH
Kalpesh

-----------------------------------------------------------

To stop getting this e-mail, or change how often it arrives, go to your E-mail 
Settings.
http://groups.msn.com/bdotnet/_emailsettings.msnw

Need help? If you've forgotten your password, please go to Passport Member Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help

For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact

If you do not want to receive future e-mail from this MSN group, or if you received 
this message by mistake, please click the "Remove" link below. On the pre-addressed 
e-mail message that opens, simply click "Send". Your e-mail address will be deleted 
from this group's mailing list.
mailto:[EMAIL PROTECTED]

Reply via email to