Following example does not represent the actual class and issue, it has been adapted for various reasons.
I have a List<EnginePart> populated with objects containing byte KeyID, int Length, byte[] Value. Each object was created sequentially and has its own meaning. The list represents "parts to be replaced" and we want to output that to a sales person in a nice format, so he can tell that to the customer. Each part has its own id, lets say 0x20 - cylinder, 0x40 - oil filter.
Now i'd like to add/display a human readable string to each object in a nice way, without iterating through a foreach and checking
if(enginePart.key =="0x20") Console.WriteLine("Cylinder rotation count is " + enginePart.value).
if(enginePart.key =="0x40") Console.WriteLine("Oil filter only filters " + enginePart.value + " of oil).
Is there any other, nicer way to do it? Creating a new class for each engine part is not a possibility.
So far I've come up with 3 possible solutions;
1) Iterate through the list and have a bunch of ifs and WriteLines
2) Add a string to the object on creation, but in that case we still have if statements
3) Create some enum and use that on object creation
ToStringin your class.