Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7747803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:37:13+00:00 2026-06-01T10:37:13+00:00

The idea is simple. Make a struct for Departments of a store, give it

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T10:37:15+00:00Added an answer on June 1, 2026 at 10:37 am

    One more potential solution is to make another class for the _buys array:

    class Buys
    {
        private double[] _buys;
    
        public Buys (int capacity)
        {
            _buys = new double[capacity];
        }
    
        public double this[int index]
        {
            get { return _buys; }
            set 
            {
                if (value > 100)
                {
                    if (Department == "CLOTH")
                        value = value * .95;
                    if (Department == "FOOD")
                        value = value * .90;
                    if (Department == "OTHER")
                        value = value * .97;
                }
                _buys = value;
            }
        }
    }
    
    struct Departments
    {
        public string Department;
        public Buys Buys;
    }
    
    static void Main()
    {
        var departments = new Departments[3];
        departments[0].Department = "CLOTH";
        departments[1].Department = "FOOD";
        departments[2].Department = "OTHER";
        departments[0].Buys = new Buys(5);
        departments[0].Buys[0] = 105;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So, my idea is quite simple: print all of the possible combinations given X
The general idea is pretty simple, I want to make a script for a
I am trying to make a simple game under Qt 4.6. The idea is
I want to make rather simple database, which should store videofiles, and soundfiles. I
I'm trying to make a simple php shopping cart. I don't have any idea
I am trying to make a simple text-based game in Python. The idea of
I have an idea for a simple program to make that will help me
OK, the idea is simple. Every wordpress site is uses categories and tags taxonomies
I'm developing a control which inherits from a System.Windows.Form.Panel. The idea is very simple:
The idea is to write a simple bookmarklet. If the question is a possible

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.