-3

Get the message:

"Error 1 Inconsistent accessibility: parameter type 'Assignment_5.Address' is less accessible than method 'Assignment_5.ContactManager.AddContact(string, string, Assignment_5.Address)' C:\Users\OscarIsacson\documents\visual studio 2012\Projects\Assignment 5\Assignment 5\ContactFiles\ContactManager.cs 24 21 Assignment 5 "

this is the method code(all classes are public):

    private List<Contact> m_contactRegistry;

    public bool AddContact(string firstName, string lastName, Address adressIn) 
    {
        Contact contactIn = new Contact(firstName, lastName, adressIn);

        m_contactRegistry.Add(contactIn);
        return true;
    }

    public bool AddContact(Contact ContactIn)
    {
        m_contactRegistry.Add(ContactIn);
        return true;
    }

and the address class:

namespace Assignment_5
{
    public class Address
    {
        private string m_street;
        private string m_zipCode;
        private string m_city;
        private Countries m_country;

        public Address() : this (string.Empty, string.Empty, "Göteborg")
        {

        }
        public Address(string street, string zip, string city)
            : this(street, zip, city, Countries.Sweden)
        { 

        }
        public Address(string street, string zip, string city, Countries country)
        {

        }

        public string Street;
        public string City;
        public string ZipCode;
        public Countries Country;

        /// <summary>
        /// This function simply deletes the "_" from country names as saves in the enum.
        /// </summary>
        /// <returns>the country name whitout the underscore char.</returns>
        public string GetCountryString()
        {
            string strCountry = m_country.ToString();
            strCountry = strCountry.Replace("_", " ");
            return strCountry;
        }

        /// <summary>
        /// Method that overrides the ToString method
        /// </summary>
        /// <returns>Formatted string with address detail on one line</returns>
        public override string ToString()
        {
            return string.Format("{0, -25} {1,-8} {2, -10} {3}", m_street, m_zipCode, m_city, GetCountryString());
        }

    }
}
Jesse C. Slicer
  • 19,901
  • 3
  • 68
  • 87
  • 1
    What's the visibility of `Address` ? – Bart Friederichs Aug 12 '13 at 20:54
  • 1
    "all classes are public" is clearly not true because `Address` is not... Please post `Address` definition too... – Alexei Levenkov Aug 12 '13 at 20:55
  • 1
    It's most likely that the class that this is in is public, but the class Address is private or has no access modifier. Make it public – devshorts Aug 12 '13 at 20:55
  • 2
    Have you bothered to google this error? It's fairly obvious what the issue is, as pointed out by the other commenters. – tnw Aug 12 '13 at 20:55
  • 1
    possible duplicate of [Inconsistent accessibility error with the following c# code. Why?](http://stackoverflow.com/questions/524761/inconsistent-accessibility-error-with-the-following-c-sharp-code-why) in addition to other duplicates... – tnw Aug 12 '13 at 20:56
  • i have seen the other "duplicates" but my classes are all public – user2676444 Aug 12 '13 at 21:19
  • @user2676444 One possibility is that the class wasn't public before, you changed it to make it public, but you're compiling with an older version of the assembly where it's still internal. –  Aug 12 '13 at 21:24
  • Are there other compilation errors? Since you've confirmed that it's public, I bet there's something else unrelated which is breaking during compilation, and once you fix that, this error will just disappear. – Joe Enos Aug 12 '13 at 21:56
  • @hvd thanx its woring when i restarted visual studio – user2676444 Aug 12 '13 at 22:28

3 Answers3

3

The Address class is either protected, private or internal for you to get this error. Note that classes are internal by default in C#.

Bart Friederichs
  • 33,050
  • 15
  • 95
  • 195
1

I think that Address might not be a public class. you should make it so

1

The Address class is not public.

You are receiving this error because you are referencing a non-public class on a public method. Callers of this code would have access to the AddContact method, but do not have access to the Address class. This means it would be impossible for anyone to call AddContact.

shf301
  • 31,086
  • 2
  • 52
  • 86