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

C# 无法声明具有不同属性类型的属性,c#,C#,在链接上,我向您展示了我程序中的所有课程 我的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 ad

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

我的
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;

但为什么我的财产会有问题呢?我怎样才能解决这个问题,使它发挥作用?提前感谢

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

它告诉您这些类型是私有的或受保护的,但您正在尝试使用公共getter和setter来公开它们。公开课程

确保

客户文件。电话
客户文件。电子邮件 客户文件。地址 客户文件。国家


是公共的。

它看起来像是在创建CustomerFile时。Phone类它看起来像:

class Phone { }
这意味着该类是内部的。不能通过公共属性公开内部类。那是疯狂的谈话

要修复此问题,您应该将类更改为public:

public class Phone { }
或待内部的属性:

 internal CustomerFiles.Phone phone { get; set; } 

首先将所有类型更改为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; }

或者您必须单独访问它们吗

/试试这个

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

}

否则调用phone属性的人无法知道什么是CustomerFile。phone是因为它不是公共的。请记住,命名属性的正确方法是使用大写字母。该图像不是类图:(非常感谢您解决了这个问题。我遇到的下一个问题是:无法将类型“string”隐式转换为指向contact.PhoneData=tbphone.Text的“CustomerRegister1.CustomerFiles.Phone”;我将在黑暗中大胆尝试,猜测1,Text是字符串,2,PhoneData是电话,3,字符串和电话不是一回事。它想要你需要写一点代码将文本转换成手机。另外,既然你原来的问题已经得到了回答,那么礼貌的做法是对所有帮助你的答案进行投票。这会让每个人都感到高兴。
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; }

}