-3

获取消息:

“错误 1 ​​可访问性不一致:参数类型 'Assignment_5.Address' 的可访问性低于方法 'Assignment_5.ContactManager.AddContact(string, string, Assignment_5.Address)' C:\Users\OscarIsacson\documents\visual studio 2012\Projects\Assignment 5\分配 5\ContactFiles\ContactManager.cs 24 21 分配 5"

这是方法代码(所有类都是公共的):

    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;
    }

和地址类:

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());
        }

    }
}
4

3 回答 3

3

该类Addressprotected,privateinternal为您获取此错误。请注意,internal默认情况下,类在 C# 中。

于 2013-08-12T20:55:20.593 回答
1

我认为这Address可能不是一个public class. 你应该这样做

于 2013-08-12T20:55:30.940 回答
1

Address不是public

您收到此错误是因为您在方法上引用了非公共类public。此代码的调用者将有权访问该AddContact方法,但无权访问Address该类。这意味着任何人都无法拨打电话AddContact

于 2013-08-12T20:56:53.907 回答