Solved

member names cannot be same as their enclosing types

Posted on 2009-07-12
2
692 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
[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
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
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…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

729 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