On Wed, 21 Jan 2004 01:21:05 -0800, Josema
<an*******@discussions.microsoft.com> wrote:
Hi to all,
I would like to know what are the differences between:
protected string mystring; (and after use that like
this.mystring=anything)
and this...
protected string mystring
public string MyString
{
get{return mystring;}
set{mystring=value;}
}
Thanks in advance.
Josema.
Apart from that the second won't compile because you are missing a ; as
well as return mystring before mystring is valid will cause unwanted
things :P
The second will keep the control of the variable mystring private (you
should use private, not protected) while exposing limited control over the
content of it. In your example it doesn't make much difference, but
consider this.
private string mystring;
public string MyString
{
get{return mystring}
set
{
if(DoesNotContainUnwantedValues(value))
mystring = value;
}
}
This way your class has something to say about what you can change
mystring to (or MyString since mystring is invisible to the outside world).
thingy.MyString = goodword; // will be accepted
thingy.MyString = badword; // will be rejected
--
Using M2, Opera's revolutionary e-mail client:
http://www.opera.com/m2/
For a laugh, try web browsing with Opera's User Mode and Nostalgia enabled