473,396 Members | 1,772 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,396 software developers and data experts.

Writing Properties

6.10 Writing Properties
In C# name the property name should "shadow" the private variable name
that it represents differing only by case; Colour and colour for
example. But this would only apply when the variable that the property
represents is private, otherwise case-insensitive languages like
Visual Basic would have trouble accessing two members inside the type.

It is not possible to "shadow" the property name in Visual Basic, as
the language is case-insensitive. So the private variable can have an
alternate name or an underscore at the beginning, e.g. _colour.

[C#]
public string Colour
{
get
{
return colour;
}
set
{
colour = value;
}
}

[Visual Basic]
Public Property Colour As String
Get
Return _colour ' Can't use colour VB is case-insensitive
End Get
Set(ByVal _colour As String)
Me._colour = _colour
End Set
End Property
Nov 16 '05 #1
3 1207
Rasika Wijayaratne wrote:
It is not possible to "shadow" the property name in Visual Basic, as
the language is case-insensitive. So the private variable can have an
alternate name or an underscore at the beginning, e.g. _colour.


Which should be the norm anyway, also in C#: using case distinction for
the distinction between differen variables / types is extremely
ambiguous. It makes code harder to read, harder to write and harder to
debug. An underscore in front of private members' names has been one of
the C++-conventions for a long time now and in my opinion it's one of
the better ones.

--
Konrad -
http://madrat.net/
Nov 16 '05 #2
Konrad L. M. Rudolph <ko************@madrat.net> wrote:
Rasika Wijayaratne wrote:
It is not possible to "shadow" the property name in Visual Basic, as
the language is case-insensitive. So the private variable can have an
alternate name or an underscore at the beginning, e.g. _colour.


Which should be the norm anyway, also in C#: using case distinction for
the distinction between differen variables / types is extremely
ambiguous. It makes code harder to read, harder to write and harder to
debug. An underscore in front of private members' names has been one of
the C++-conventions for a long time now and in my opinion it's one of
the better ones.


I've never found it at all hard to disambiguate between (say) colour
and Colour. I also find it significantly easier to read that than
_colour - the extra underscore makes my brain judder slightly when
reading it.

Each to their own (when it comes to naming conventions for private
variables) but I've never found it to be a problem.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #3
> > It is not possible to "shadow" the property name in Visual Basic, as
the language is case-insensitive. So the private variable can have an
alternate name or an underscore at the beginning, e.g. _colour.


Which should be the norm anyway, also in C#: using case distinction for
the distinction between differen variables / types is extremely
ambiguous. It makes code harder to read, harder to write and harder to
debug. An underscore in front of private members' names has been one of
the C++-conventions for a long time now and in my opinion it's one of
the better ones.

I disagree. if you see a variable starting with a small letter you
immediately know that it is a private field.
If you see oen starting with uppercase letter you know that its a property
or public.
Anyway, the uppercase and lowercase versions should have the same meaning
(as long as your properties does not have sideeffects).

--
cody

Freeware Tools, Games and Humour
http://www.deutronium.de.vu || http://www.deutronium.tk
Nov 16 '05 #4

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

Similar topics

1
by: Tristan | last post by:
Hi, In my application I need to store pen objects in a file so they can be read in at a latter stage from the file to recreate the pen objects in memory. I'm currently doing this by hand,...
102
by: Xah Lee | last post by:
i had the pleasure to read the PHP's manual today. http://www.php.net/manual/en/ although Pretty Home Page is another criminal hack of the unix lineage, but if we are here to judge the quality...
2
by: Nathan Sokalski | last post by:
I am an ASP.NET developer who would like to start learning about writing ASP.NET custom controls using VB.NET. I already have a reasonable amount of knowledge with making ASP.NET pages, and am...
2
by: Nathan Sokalski | last post by:
I am an ASP.NET developer who would like to start learning about writing ASP.NET custom controls using VB.NET. I already have a reasonable amount of knowledge with making ASP.NET pages, and am...
5
by: David Veeneman | last post by:
I'm opening a JPG file to read and write its EXIF properties. I'm using very simple code to open the file: myBitmap = new Bitmap(filePath); Reading and writing the properties is working fine,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.