• 0

[C#] "class name is not valid at this point" error


Question

Hey guys,

I'm trying to call a method with 1 argument. However, no matter where I call the method, I get an error saying "class name is not valid at this point."(and in certain places, I also get an error saying "redundant empty statement") The argument I'm calling is a class variable.

Here is my code so it makes a bit more sense with what I'm trying to say

PrintReceipt(Pump aPump);	//Method I'm trying to call

		public static void PrintReceipt(Pump aPump)	//The actual method
		{
			const double amountDispensed = 0;
			DateTime currTime = DateTime.Now;

			Console.WriteLine("\nAUTOMATED FUEL DELIVERY SYSTEM");
			Console.WriteLine("\nRECEIPT");
			Console.WriteLine("\nDate : {0:d}", currTime);
			Console.Write("\nPaid for {1:#.##} litres of ", aPump.getPrice(), amountDispensed);
		}

If anyone can help me out, that'd be great.

Thanks in advance,

Britt.

6 answers to this question

Recommended Posts

  • 0
  Pc_Madness said:
I think I see her problem,

PrintReceipt(Pump aPump);

Is that how your calling the function? You don't need to include the data type (aka Pump) when calling functions.

PrintReceipt(aPump);

should do the job. :)

Thanks for the reply guys!

Pc_Madness, I've tried that, and it throws an error saying a ')' is expected.

  ork said:
If you can post your complete usage in the class maybe i can help. You can snip method implementations if they are large to post.

Yep I'll post my code up

  • 0

            // Scenario 1 - Enter cash limit 
            if (aSystem.getCardReader().getCardSatus() == SystemController.CardStatus_Valid)
            {

                Pump aPump = customer1.getPump();
                // Fuel selection
                aPump.setFuelType(FuelPriceType.Unleaded);
                // set cash
                aPump.setPrice(40);       
                // check credit limit
                // check fuel price with customers selection
                if (customer1.getCreditLimit() > aPump.getPrice())
                {
                    double fuelDelivery = aPump.getPrice() / FuelPriceType.UnleadedPrice;

                    aPump.activate();
                    if (aTank.getTotalLevel() > fuelDelivery)
                    {
                        aPump.setFuelDispensed(fuelDelivery);
                    }
                    PrintReceipt(Pump aPump);
                    aPump.deactivate();
                    aTank.removeFuel(fuelDelivery);
                    customer1.setCreditLimit(customer1.getCreditLimit() - aPump.getPrice());
                    DateTime currTime = DateTime.Now;

Correction: it's no longer throwing the original error which I posted about, however, it's still saying that a ')' is expected even when I include the data type (which is Pump in this case)

  • 0

Where abouts is it saying that the ) is expected? I can't see any missing brackets from the code you've posted.

You definitely don't need to include the data type when calling your function. I don't even know how that could compile to be honest since I would think that it would have a bitch about you declaring a variable with the same name in the same scope. (you're basically passing PrintReceipt a blank Pump)

Edit: Go away wrack you crazy fellow. :p

p.s. Hi :p

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.