Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Error Message when calling Business Class
Message
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Titre:
Error Message when calling Business Class
Versions des environnements
Environment:
C# 3.0
OS:
Vista
Database:
Visual FoxPro
Divers
Thread ID:
01465507
Message ID:
01465507
Vues:
81
I have a couple ListBoxes (this is for demonstrating multi-tier) in whcih a person double-clicks on th eleft ListBox to select a Book he wants to buy. The book info is passed to the 2nd ListBox on the right.

The user hits the Calculation button wherein the BusinessClass class is called passing an array parameter containing the books the Buyer selected. The book info also includes the price of each book on the right side of the selecteditem. That isn't the problem.

My problem is that I am passing an array from the 2nd ListBox (what the Buyer is purchasing) in which the books's prices only are listed and then receive an error message in which is stated the following: "Argument type 'string' is not assignable to parameter type 'string[]' ". The BusinessClass' constructor uses a string[] array for its parameter, and the call uses an arrray for its calling parameter. So, I cannot understand why I am getting the before-mentioned error message. Okay, I am new to this, which makes me understand that somehow I am making a mistake, and it is somewhere, but I sure as heck don't see it. :)

The call goes like this:
// You now have the array string containing the dollar amounts.
// Send the priceListItemsString array to BusinessClass as a parameter.
BusinessClass businessClass =
    new BusinessClass(priceListItemsString[arrayLength]);
The code in the BusinessClass is as follows:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ComputerBookStore
{
    class BusinessClass
    {
        private static decimal totalDecimal;
        private static int countInteger;

        public BusinessClass(string[] arrayListOfPrices)
        {
            // Need to loop through string array which contains all the prices.
            // All book prices need to be converted to decimal and then added up.
            int quantityOfBooks = arrayListOfPrices.Count();
            for (int i = 0; i < quantityOfBooks; i++)
            {
                totalDecimal += decimal.Parse(arrayListOfPrices[i]);
            }
            countInteger = quantityOfBooks;
        }

        public static decimal Total
        {
            get
            {
                return totalDecimal;
            }
        }

        public static int Count
        {
            get
            {
                return countInteger;
            }
        }
    }
}
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform