I usually make enumerations separate from classes, but when my CS teacher was teaching us about enums, he put it inside the class, and when it came time to set a variable of the enum outside of the class, he told us to just pass a string to the class evaluate that with a method inside the class itself. Is there any reason why one would do this? Is it bad practice to put enums outside of the class in which it is used?
Sorry if it's hard to understand what I'm trying to say. I'll try to make some code snippets to make it easier to understand.
Here we go:
What I usually do:
enum AnEnum {
Bla,
Blah
}
public class A {
AnEnum anEnum;
public A(AnEnum newAnEnum) {
anEnum = newAnEnum;
}
}
What he told us to do (I don't know if that string evaluation is 100% right, but this is pretty much it)
public class A {
enum AnEnum {
Bla,
Blah
}
AnEnum anEnum;
public A(string newAnEnum) {
if(newAnEnum == "Bla") anEnum = AnEnum.Bla;
else anEnum = AnEnum.Blah;
}
}