I have a Person object with two constructors – one takes an int (personId), the other a string (logonName). I would like another constructor that takes a string (badgeNumber). I know this can’t be done, but seems it might be a common situation. Is there a graceful way of handling this? I suppose this would apply to any overloaded method. Code:
public class Person { public Person() {} public Person(int personId) { this.Load(personId); } public Person(string logonName) { this.Load(logonName); } public Person(string badgeNumber) { //load logic here... }
…etc.
You might consider using custom types.
For example, create LogonName and BadgeNumber classes.
Then your function declarations look like…
Such a solution might give you a good place to keep the business logic that governs the format and usage of these strings.