C
C#2y 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
GladiatorOP2y ago
Because I can iterate over or store tasks using tasktype for example in dictionary
Thinker
Thinker2y ago
If None is supposed to be the "default", then it should be 0, because then default(TaskType) will be None
Gladiator
GladiatorOP2y ago
OK, yes
Thinker
Thinker2y ago
The enum value that is 0 is always the default
Gladiator
GladiatorOP2y 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
Accord2y ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server