Solved

member names cannot be same as their enclosing types

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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

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…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

626 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