Solved

member names cannot be same as their enclosing types

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

Independent Software Vendors: 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
.NET 2008 VB and C# 6 48
Call Controller Action Method from ASPX 2 30
Convert Silverlight ERP To Angularjs,HTML5 3 59
parsing question on dynamic concatenation 3 34
In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

749 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