The idea is simple. Make a struct for "Departments" of a store, give it a variable for naming (a string called "Department"), and a array to save all buys done in that department.
Now, I want that every time that I'm gonna save a buy on a specific Department, it auto-applies a discount based on department's name and buy amount.
Now, the example class:
class Program
{
struct Departments
{
public string Department;
private double[] _buys;
public double[] Buys
{
get { return _buys; }
set
{
if (value > 100)
{
if (Department == "CLOTH")
_buys = value * .95;
if (Department == "FOOD")
_buys = value * .90;
if (Department == "OTHER")
_buys = value * .97;
}
_buys = value;
}
}
}
static void Main()
{
var departments = new Departments[3];
departments[0].Department = "CLOTH";
departments[1].Department = "FOOD";
departments[2].Department = "OTHER";
departments[0].Buys = new double[5];
departments[0].Buys[0] = 105;
}
}
Note the line departments[0].Buys[0] = 105
, that's the way that I want to save bought things, "Code-Simple"...
Now, note the property Buys
of the struct, it's an "Array Property". Then, when I use the value > 100
condition it gives an obvious error, can't cast from double
to double[]
.
The question... how can I write a right condition for value > 100
, what else must be put on the stuct to achieve this?
I've tried with "Indexers", but as long as I've tried I can't make it take assignemts via departments[0].Buys[0] = 105
in the right way.
Please note that I wanna keep this schema, specially for the facility of simply say departments[0].Buys[0] = 105
to asing buyings
EDIT:
The previous struct "Departments" is done for example-purposes only. I won't answers about making it by another way to have right "Departments", I want an answer of how to make the set parameter work on individual elements of arrays