# [.net] Property naming conventions [solved]

This topic is 3584 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I just started learning C# a few days ago and I'm a bit confused about naming my properties when they have class types. With get and set accessors from C++, I never had this trouble.
class MyClassWithAnImage
{
public Image Image // <-- what to name this?
{
get { return _image; }
set { _image = value; }
}
private Image _image;
}

GetImage and SetImage don't have this issue. Calling it Picture or Bitmap or something seems like a cop-out. Lower-case image doesn't match other .NET stuff. [Edited by - jdindia on January 21, 2009 7:50:03 PM]

##### Share on other sites
You can call it Image. The C# is smart enough to know when you want the type and when you want the property.

##### Share on other sites
Uhh, I didn't expect that answer. Thank you sir. It helps.

##### Share on other sites
While I realise that you can do this, you really shouldn't. Such a thing would be a nightmare for another program to read. Rather, give it a name that describes what the image is supposed to be. If you must keep things simple, then use a term that is the equivolent ie Picture instead of Image.

Granted, that's not much better, but I'm just trying to work within the example.

##### Share on other sites
But sometimes Image really is the best name, in which case it's perfectly fine to use it. The .NET framework has many examples of this, such as SolidBrush.Color.

##### Share on other sites
I never open up the namespaces so, in your case, my code would look like:
class MyClassWithAnImage{    public System.Drawing.Image Image    {        get { return _Image; }        set { _Image = value; }    }    private System.Drawing.Image _Image;}

Much easier for an external reader, as he won't have to guess if Image (the class) is the default System.Drawing.Image or some user-defined class.

##### Share on other sites
I suggest calling it something that suggests the role of the image for example.

BackgroundImage (if the image is the background image)

ImageGlyph (if the image is some sort of decoration ...)

or if the class is supposed to be an image wrapper of some sort you can call it

SourceImage

or if the image is both a source and a destination (meaning it is operated upon/changed) then call it

ImageBuffer or simply Canvas

but in the end Image is good also if the role of the property is truly generic.

1. 1
Rutin
40
2. 2
3. 3
4. 4
5. 5

• 9
• 19
• 20
• 14
• 14
• ### Forum Statistics

• Total Topics
633382
• Total Posts
3011581
• ### Who's Online (See full list)

There are no registered users currently online

×