I'm relatively new to C #, so the concept of defaults is a bit confusing to me.
I currently have an object that contains two values String, serialNumberand fullPath. This is a simple object containing nothing but these two lines and the corresponding getter methods (they should not change after the object is created, therefore, the absence of setter methods).
I want to put a list of these objects in CheckedListBox. I want the field to display only the serial number, and not the full path. According to MSDN, it CheckedListBox uses the default String value for an object. How to set value serialNumberwhen creating an object? Again, this should not change subsequently. In addition, I am not a big fan of keywords getand set(I come from the Java background), so if possible, I would like to do this with more ordinary getters / setters, as I made below for the convenience of reading code.
class ModuleData
{
private String serialNumber;
private String fullPath;
public ModuleData(String serialNumber, String fullPath)
{
this.serialNumber = serialNumber;
this.fullPath = fullPath;
}
public String getSerialNumber()
{
return serialNumber;
}
public String getFullPath()
{
return fullPath;
}
public String toString()
{
return serialNumber;
}
public String DefaultValue
{
return serialNumber;
}
}
source
share