无法声明具有不同属性类型的属性

时间:2011-12-13 14:02:49

标签: c#

http://imageshack.us/f/403/kasta6.png/

在链接上,我会在程序中向您展示我的所有课程

我的customerframe类中有属性,如下所示:

 public string firstName { get; set; }
 public string lastName { get; set; }
 public CustomerFiles.Phone phone { get; set; }
 public CustomerFiles.Email email { get; set; }
 public CustomerFiles.Address addressinfo { get; set; }
 public string city { get; set; }
 public CustomerFiles.Countries countryinfo { get; set; }
 public string street { get; set; }
 public string zipcode { get; set; }

但我的问题是,当这样做时,我得到指向这4个属性的错误

public CustomerFiles.Phone phone { get; set; }
public CustomerFiles.Email email { get; set; }
public CustomerFiles.Address addressinfo { get; set; }
public CustomerFiles.Countries countryinfo { get; set; }

错误就是这个

  

不一致的辅助功能属性类型不易访问   属性

在课堂上继续下去,我会做以下事情:

        contact.FirstName = tbFirstName.Text;
        firstName = contact.FirstName;

        contact.LastName = tbLastName.Text;
        lastName = contact.LastName;

        contact.PhoneData = tbCellPhone.Text;
        phone = contact.PhoneData;

        contact.EmailData = tbHomePhone.Text;
        email = contact.EmailData;

        //inside address class
        address.City = tbCity.Text;
        city = address.City;

        address.Country = cbCountry.Text;
       countryinfo = address.Country;

        address.Street = tbStreet.Text;
        street = address.Street;

        address.ZipCode = tbZipCode.Text;
        zipcode = address.ZipCode;

但为什么我的财产出现问题?如何解决这个问题才能使其发挥作用?提前谢谢

6 个答案:

答案 0 :(得分:8)

显然,类型CustomerFiles.Phone(或其包含类型CustomerFiles(如果它是类型而不是命名空间)不具有public的可见性。由于您创建的返回类型的属性是public,因此类型本身也必须为public

答案 1 :(得分:2)

首先将所有类型更改为Public以避免可访问性问题。 其次,你不能只改变

 public CustomerFiles.Phone phone { get; set; }
 public CustomerFiles.Email email { get; set; }
 public CustomerFiles.Address addressinfo { get; set; }
 public CustomerFiles.Countries countryinfo { get; set; }

public CustomerFiles customer {get; set;}

或者您是否必须单独访问它们?

/ J

答案 2 :(得分:1)

看起来,当您创建CustomerFiles.Phone类时,它看起来像:

class Phone { }

这意味着该课程是内部的。您不能通过公共属性公开内部类。那是疯狂的谈话。

要修复,您应该将类​​更改为公共类:

public class Phone { }

或者属于内部的财产:

 internal CustomerFiles.Phone phone { get; set; } 

答案 3 :(得分:0)

它告诉你这些类型是私有的还是受保护的,但是你试图用公共getter和setter来表示它们。将课程公开

答案 4 :(得分:0)

确保

  

CustomerFiles.Phone
  CustomerFiles.Email   CustomerFiles.Address   CustomerFiles.Countries

是公开的。

答案 5 :(得分:0)

试试这个

class customerframe
{
public string firstName { get; set; }
 public string lastName { get; set; }
 public string city { get; set; }
 public string street { get; set; }
 public string zipcode { get; set; }
 public CustomerFiles CustomerFiles { get; set; }
}

public class CustomerFiles 
{
public Phone phone { get; set; }
public Email email { get; set; }
public Address addressinfo { get; set; }
public Countries countryinfo { get; set; }

}