(Please read the comments in the question first for more context about this answer)
Hi, well, see now we got a better picture. First you have these fruits that have certain qualities to each. So you want to make a class or struct to represent these fruits and their qualities/properties:
class Fruit {
public string name="";
public float moist=0f;
public float freshness=0f;
public Fruit (string name, float moist, float freshness) {
this.name=name;
this.moist=moist;
this.freshness=freshness;
}
}
Then you want to modify the Set class to hold these fruits. So instead of using int, you will use Fruits:
class Set {
List<Fruit> fruits=new List<Fruit>();
public void AddFruits (params Fruit[] fruits) { //This will accept either an array or an indefinite number of parameters
this.fruits.AddRange(fruits);
}
public List<Fruit> Fruits () { //Return fruits list
return fruits;
}
public void AddSet (Set set) { //Adds a Set fruits to this Set fruits
fruits.AddRange(set.Fruits());
}
public static Set MergedSets (params Set[] sets) { //Returns a new Set which is the result of merging several Sets
Set mergedSet=new Set();
foreach(Set set in sets)
mergedSet.AddSet(set);
return mergedSet;
}
public List<Fruit> GetFruitsByMoistAsc () { //Returns the list of fruits according to their moist, ascending
List<Fruit> fruits=new List<Fruit>();
fruits.AddRange(this.fruits);
fruits.Sort((x, y) => x.moist.CompareTo(y.moist));
return fruits;
}
public List<Fruit> GetFruitsByMoistDsc () { //Returns the list of fruits according to their moist, descending
List<Fruit> fruits=new List<Fruit>();
fruits.AddRange(this.fruits);
fruits.Sort((x, y) => y.moist.CompareTo(x.moist));
return fruits;
}
public List<Fruit> GetFruitsByFreshnessAsc () { //Returns the list of fruits according to their freshness, ascending
List<Fruit> fruits=new List<Fruit>();
fruits.AddRange(this.fruits);
fruits.Sort((x, y) => x.freshness.CompareTo(y.freshness));
return fruits;
}
public List<Fruit> GetFruitsByFreshnessDsc () { //Returns the list of fruits according to their freshness, descending
List<Fruit> fruits=new List<Fruit>();
fruits.AddRange(this.fruits);
fruits.Sort((x, y) => y.freshness.CompareTo(x.freshness));
return fruits;
}
}
Then you would first define your fruits, and then add them to your fixed sets of fruits, the baskets. Then you would add all the fruits from all the chosen baskets into one big pile. Then pick whatever fruit by whatever attribute:
public void blah() {
//Define fruits for a basket
Fruit apple1=new Fruit("Golden Delicious", 80f, 70f);
Fruit apple2=new Fruit("Red Delicious", 60f, 20f);
Fruit apple3=new Fruit("Gala", 40f, 78f);
Fruit apple4=new Fruit("Fuji", 50f, 22f);
Fruit apple5=new Fruit("Granny Smith", 33.5f, 37f);
Fruit apple6=new Fruit("Honeycrisp", 24f, 91f);
//Add fruits to basket
Set apples2B=new Set();
apples2B.AddFruits(apple1, apple2, apple3, apple4, apple5, apple6);
//More fruits... more baskets...
Set kiwi3G=new Set();
//ETC.
//After all 4 baskets were chosen, merge all baskets fruits into one pile
Set fruitsPile=Set.MergedSets(apples2B, kiwi3G);
//I want to pick the most fresh fruit from the pile:
Fruit freshestFruit=fruitsPile.GetFruitsByFreshnessDsc()[0];
//ETC.
}
I think this would be a valid way of handling the situation. If you need further help with different areas of the matter, like setting up drop drown boxes and the like, you should probably open new questions with more specific questions.
As you said, arrays are of fixed length once they’re initialized, although I presume C# provides ways to dynamically grow them, but usually you’re better off sticking to Lists as they’re far more manageable. Drawbacks of lists… they’re possibly a little slower, and take up more memory, but usually nothing one should be too concerned about. For all I know C# could be handling arrays and list in virtually the same way internally. In the old days you could definitely assert the aforementioned about arrays and vectors in C/C++ but I’m not quite sure to what extent this applies to C#. As for enums, they’re really just definitions you would use at build time, not actual values you can pick at run time, I hope I’m making some sense… something like flags to guide your code, but not actual values. So in the present case I don’t think they have much use.
Maybe you should try to understand your problem yourself first. > I get slightly confused just trying to > write this text, I hope someone can > understand it How could we if you can't?
– hexagoniusWhy don't you instead state what final goal you want to achieve, rather than what you want to do? Honestly you're not making much sense. You can't compare values of different enums even if these values are named equally. Also AFAIK you cannot dynamically modify enums.
– ecv80