Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Function Return Values in C#

Posted on 2006-07-23
5
Medium Priority
?
391 Views
Last Modified: 2010-08-05
I'm currently learning C# and moderatly know VB.NET. I cannot figure out what I'm doing wrong in this practice example. I am getting an error when I compile the project: "cannot convert from method group to object" for ThisInvoice.GetInvoiceAmount. Any help would be appreciated. Heres the code -

using System;
using System.Collections.Generic;
using System.Text;

    class Invoice
    {
        private string partNumber, description;
        private int quantity;
        private decimal price;

        public Invoice()
        {
            partNumber = "";
            description = "";
            quantity = 1;
            price = 0;
        }
       
        public string PartNumber
        {
            get
            {
                return partNumber;
            }
            set
            {
                partNumber = value;
            }

        }

        public string Description
        {
            get
            {
                return description;
            }
            set
            {
                description = value;
            }
        }

        public int Quantity
        {
            get
            {
                return quantity;
            }
            set
            {
                quantity = value;
            }
        }

        public decimal Price
        {
            get
            {
                return price;
            }
            set
            {
                price = value;
            }
        }

        public decimal GetInvoiceAmount()
        {          
                return Quantity * Price;            
        }
    }
0
Comment
Question by:dynamk
  • 3
  • 2
5 Comments
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 17163084
Hi dynamk;

The posted class looks fine. How are you creating the class and initializeing the variables and calling GetInvoiceAmount()? Can you post the code where you do this?

Fernando
0
 

Author Comment

by:dynamk
ID: 17163160
Here's the calling class:

using System;
using System.Collections.Generic;
using System.Text;


    class InvoiceTest
    {            
        static void Main(string[] args)
        {
            Invoice ThisInvoice = new Invoice();
            ThisInvoice.PartNumber = "124578ab";
            ThisInvoice.Description = "Widget1";
            ThisInvoice.Price = Convert.ToDecimal(7.99);

            Console.WriteLine("Please enter quantity desired:");
            ThisInvoice.Quantity = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Your invoice details are as follows:\nPart Number: {0}\nDescription: {1}\nPrice: {2}\n",ThisInvoice.PartNumber,ThisInvoice.Description,ThisInvoice.Price);
            Console.WriteLine("Quantity: {0}  ", ThisInvoice.Quantity);
            Console.WriteLine("Total Amount: {0}", ThisInvoice.GetInvoiceAmount);
        }
    }
0
 
LVL 64

Accepted Solution

by:
Fernando Soto earned 200 total points
ID: 17163182
Hi dynamk;

Change this line in your code

            Console.WriteLine("Total Amount: {0}", ThisInvoice.GetInvoiceAmount);

To this

            Console.WriteLine("Total Amount: {0}", ThisInvoice.GetInvoiceAmount());

Fernando
0
 

Author Comment

by:dynamk
ID: 17163277
Thanks, I really have to get used to the differences between VB.Net.
0
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 17163289
No problem, glad I was able to help.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question