473,395 Members | 1,537 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

What are the differences between this?

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 mystrin
public string MyStrin

get{return mystring;
set{mystring=value;
Thanks in advance
Josema.
Nov 15 '05 #1
5 1087

"Josema" <an*******@discussions.microsoft.com> wrote in message
news:E4**********************************@microsof t.com...
Hi to all,

I would like to know what are the differences between:

protected string mystring; (and after use that like this.mystring=anything) this produces a protected string field. This field is accessable only in the
current class and its inheritors. and this...
protected string mystring
public string MyString
{
get{return mystring;}
set{mystring=value;}
}
This creates a protected string field and a public property to access that
string. Practically this means that any class can access mystring(via
MyString).
Thanks in advance.
Josema.

Nov 15 '05 #2
Hi Josema,
protected string mystring;
allows _only_ derived classes of the enclosing class type
to access the mystring field. whereas the following
protected string mystring
public string MyString
{
get{return mystring;}
set{mystring=value;}
}
allows 'MyString' property to grant public access to
the 'mystring' protected field.
This means that all classes (not only derived ones) would be
able to modify/access the 'mystring' field through 'MyString'.

Regards,
Aravind C
"Josema" <an*******@discussions.microsoft.com> wrote in message
news:E4**********************************@microsof t.com... 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.

Nov 15 '05 #3
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
Nov 15 '05 #4
Josema <an*******@discussions.microsoft.com> writes:
I would like to know what are the differences between:

protected string mystring; (and after use that like this.mystring=anything)
Here you can access mystring from the class itself and its inheriting
classes. The drawback is that mystring isn't "controlled", so i can
assign quite everything to mystring (null value too)
and this...
protected string mystring
public string MyString
{
get{return mystring;}
set{mystring=value;}
}


Here you wrap up mystring in a public (accessible to all) property and in
get/set methods you can choose whether to allow assignment of a specific value
or not, doing some computation and so on. But you unmask mystring to inherited
classes.

Maybe in the second example masking mystring as private is better, so also
inherited classes pass through the property. Bye

--
Lawrence "Rhymes" Oluyede
http://loluyede.blogspot.com
Nov 15 '05 #5
In addition to what everyone else has told you: If that member is on a
design time control, the field (first example) will not appear in the
Properties view, even if you make it public, but the property will.

Also, (might be a little off on this one). I believe that if you mark that
control serializable, and use default serialization (as opposed to
implementing ISerializable), the fields will not serialize, but the
properties will. Might be wrong on that, but I had thought that there was
something to that.
"Josema" <an*******@discussions.microsoft.com> wrote in message
news:E4**********************************@microsof t.com...
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.

Nov 15 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

220
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
226
by: Stephen C. Waterbury | last post by:
This seems like it ought to work, according to the description of reduce(), but it doesn't. Is this a bug, or am I missing something? Python 2.3.2 (#1, Oct 20 2003, 01:04:35) on linux2 Type...
0
by: Dan Gass | last post by:
The difflib.py module and the diff.py tools script in Python 2.4 alpha 3 now support generating side by side (with intra line differences) in HTML format. I have found this useful for performing...
4
by: Mary Ellen Curtin | last post by:
I made a web page (wheee!) and decided to test it (by upload) in the W3C Validator http://validator.w3.org/ I had some errors, but as Bilbo said of Gandalf, "The explanation did not explain." ...
2
by: Patrick | last post by:
Are the differences between a search engine, a subject directory and a meta search engine significant for an ebusiness web site owner? A meta search engine merely uses ordinary existing search...
13
by: Kieran | last post by:
I am designing a content management system and I want to make sure all pages entered into it's database by users are using valid HTML. I have designed the system to use HTML 4.01 Transitional...
5
by: aaj | last post by:
Hi all can I ask a genuine question (by that I mean I'm not trolling) We are a small company and for a few years we have been building internal web apps in ASP connecting to databases etc. ...
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
1
by: Michael Nemtsev | last post by:
Any kind of differences? Were they buid on the common base or different? -- WBR, Michael Nemtsev :: blog: http://spaces.msn.com/laflour "At times one remains faithful to a cause only...
5
by: Larry__Weiss | last post by:
Can a C# program find out what language an assembly (or components thereof) is written in? - Larry
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.