#708 – A Name Must Be Unique Within A Declaration Space

When you declare an element in C#, your declaration exists within a particular declaration space.  The declaration space is the context within which you can’t have two elements declared with the same name.

One example of a declaration space is a class–within a class, you cannot have more than one member with the same name, but you can have a member with the same name in a different class.  In the example below, we define a Name property in one class and a Name method in another class.

    public class Dog
        public string Name { get; set; }
        public int Age { get; set; }

        // NO: We already have a "Name" member in this declaration space
        //public void Name()

    public class Baby
        public string BabyName { get; set; }

        public void Name(string newName)
            BabyName = string.Format("Cute little {0}", newName);

About Sean
Software developer in the Twin Cities area, passionate about .NET technologies. Equally passionate about my own personal projects related to family history and preservation of family stories and photos.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: