Solved

member names cannot be same as their enclosing types

Posted on 2009-07-12
2
687 Views
Last Modified: 2012-06-21
I am following through this tutorial to learn and I am getting an error 'member names cannot be same as their enclosing type'
can you explain how I can correct this?
namespace AddNumbers

{

    public class AddNumbers

    {

        private int _num1;

        private int _num2;

        public int num1

        {

            get

            {

                return _num1;

            }

            set

            {

                _num1 = value;

            }

        }

        public int num2

        {

            get

            {

                return _num2;

            }

            set

            {

                _num2 = value;

            }

        }

        public int AddNumbers(int n1, int n2)

        {

            return n1 + n2;

        }

    

    }

Open in new window

0
Comment
Question by:davetough
2 Comments
 
LVL 6

Accepted Solution

by:
microbolt earned 500 total points
ID: 24835715
You can't use the class name as an function name.  The function name is reserved for constructors.  Try changing

        public int AddNumbers(int n1, int n2)
        {
            return n1 + n2;
        }

TO

        public int Add(int n1, int n2)
        {
            return n1 + n2;
        }
0
 

Author Comment

by:davetough
ID: 24835784
thank you
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Split string on commas but not when enclosed in parentheses 7 47
Need a complete list of ASP.NET page load events 3 26
Remove greater than sign 3 44
Replace &lt; with < 14 56
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…
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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

910 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now