C
C#3y ago
Gladiator

❔ Nullable enums or None inside

Suppose there are some known tasks like Carry, Build, etc. A worker can be idle or busy. If they are busy, a task is assigned to them. Which one do you prefer to define task types?
public enum TaskType{
None = 0,
//...
}
TaskType Type;
public enum TaskType{
None = 0,
//...
}
TaskType Type;
public enum TaskType{
Build = 0,
//...
}
TaskType? Type;
public enum TaskType{
Build = 0,
//...
}
TaskType? Type;
Imo, The second one
6 Replies
Gladiator
GladiatorOP3y ago
Because I can iterate over or store tasks using tasktype for example in dictionary
Thinker
Thinker3y ago
If None is supposed to be the "default", then it should be 0, because then default(TaskType) will be None
Gladiator
GladiatorOP3y ago
OK, yes
Thinker
Thinker3y ago
The enum value that is 0 is always the default
Gladiator
GladiatorOP3y ago
I have a list/priority queue for each task type yes If I include None inside, I have trouble, in many situations I should ignore None Dictionary<TaskType,PriorityQueue<>>
Accord
Accord3y ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.

Did you find this page helpful?