Solved

Function Return Values in C#

Posted on 2006-07-23
5
380 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 63

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 63

Accepted Solution

by:
Fernando Soto earned 50 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 63

Expert Comment

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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How do I hide MVVM menu items in WPF/XAML? 1 55
parse string in c# 5 41
C# DataTable (in memory) vs SQL Lookups 4 75
Read top line from CSV file 14 59
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…

751 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