- Home /
Enum instead of numbers in arrays
I want to use ENUM as a way to make reading easier as I pass alot of parameters using arrays as argument for my function.
//inside the class enum eLimits { EntropyMinimum = 0, EntropyMaximum, StabilityMinimum, StabilityMaximum, ChewedFilesFrequency };
private struct virusLimits
{
private double entropyMin;
private double entropyMax;
private double stabilityMin;
private double stabilityMax;
private double chewedFilesFrequeny;
public virusLimits ( double [] args) {
//removed lots of things to make it shorter
entropyMin = args[eLimits.EntropyMinimum];
entropyMax = args[eLimits.EntropyMaximum];
stabilityMin = args[eLimits.StabilityMinimum];
stabilityMax = args[eLimits.StabilityMaximum];
chewedFilesFrequeny = args[eLimits.ChewedFrequency];
}
}
//continues the code
The result I always get is "error CS0266: Cannot implicitly convert type PetBehaviourScript.vStatus' to
int'. An explicit conversion exists (are you missing a cast?)" for each and every time I try to use enum as a number for the array... Is there a way to do it?
Answer by Jeff-Kesselman · Jun 03, 2014 at 08:53 PM
You can cast an enum to an int, or use Convert.ToInt32(value)
You can also make extension implicit casts, but I doubt that its worth the effort.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
array is pointer and float variable is not - why not? C# 1 Answer
Listing multiple objects 2 Answers