Firstly Hello, This is my first post on this forum.
I am completing a project in my second year of an IT degree. It’s a baptism of fire as it’s a tcp/ip utility in C# and my only other experience of programming in a foundation module in Java in the first year.
My problem is that part of my programm logs NIC card error codes using NetworkAdapter class Availability property. I have made an array of the error code descriptions as they are not automatically returned with the code. Obviously arrays being 0 based and the codes start at 1 I have had to put a null value as the entry in the array. Is there a more robust solution or is that the only way? I ask because i understand that null values in arrays are frowned upon.
string[] availabilityArray = new string[] {"", "Other", "Unknown", "Running or Full Power", "Warning", "In Test", "Not Applicable", "Power Off", "Off Line", "Off Duty", "Degraded", "Not Installed", "Install Error", "Power Save - Unknown" + "\n" +"The device is known to be in a power save state, but its exact status is unknown.", "Power Save - Low Power Mode" + "/n" +"The device is in a power save state, but still functioning, and may exhibit degraded performance.", "Power Save - Standby" + "/n" +"The device is not functioning, but could be brought to full power quickly.", "Power Cycle", "Power Save - Warning" + "/n" + "The device is in a warning state, though also in a power save state.",};
Many Thanks
There are multiple ways to handle this:
Subtract 1 from each error code before looking it up:
Use a dictionary:
This would also handle gaps, you could easily skip to code 10 in the above list and continue, but you would need explicit code to detect whether an error code is present in the dictionary: