tags:

views:

68

answers:

4

I want a attribute in my Hero class to have a Portrait attribute for his/her image. What object type should I use in this case?

public class Hero
{
    public string Name { get; set; }
    public string HeroType { get; set; }
    public int StartingHP { get; set; }
    public int StartingMana { get; set; }
    public Dictionary<string, string> Spells { get; set; }
    public Dictionary<string, string> Items { get; set; }        
}
A: 

How about this:

System.Drawing.Image

Andy White
+3  A: 
SLaks
+2  A: 

Beware the memory hogging some of the other answers may lead to. This is a data object right, not a UI object?

Do you know for a fact that you will always need the image for the life of the object? I would be concerned about eating up memory. It's probably better to just keep a resource identifier (file path, name in resource file, etc) and only pass that info on to image boxes. I wouldn't suggest holding on to the whole image. In winforms at least (don't know about WPF) the garbage collector isn't so hot at cleaning up images. It only sees them as a reference (i.e. an integer) because the rest of the image is basically an unmanaged object and thinks it's not a high priority for collection. Meanwhile, it could be chewing up megabytes. We got burned on a previous project of mine on that.

Jim Leonardo