Solved

member names cannot be same as their enclosing types

Posted on 2009-07-12
2
685 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
Comment Utility
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
Comment Utility
thank you
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
Article by: Ivo
Anonymous Types in C# by Ivo Stoykov Anonymous Types are useful when  we do not need to follow usual work-flow -- creating object of some type, assign some read-only values and then doing something with them. Instead we can encapsulate this read…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

762 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

6 Experts available now in Live!

Get 1:1 Help Now