2011-12-13 49 views
2

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; 

但爲什麼我的房產有問題?我怎樣才能解決這個問題,使其工作?在此先感謝

+1

有記住,命名屬性的正確方法是啓動資金。 –

+0

該圖像不是類圖:( – leppie

回答

1

它看起來就像當你創建CustomerFiles.Phone類它看起來是這樣的:

class Phone { } 

這意味着類是內部的。您不能通過公共財產公開內部類。這是瘋狂的談話。

要解決,您應該更改類是公共的:

public class Phone { } 

或屬性是內部:

internal CustomerFiles.Phone phone { get; set; } 
+0

非常感謝,解決了它。接下來的問題是這樣的:不能隱式地將類型'字符串'轉換爲'CustomerRegister1.CustomerFiles.Phone'指向contact.PhoneData = tbCellPhone.Text; – user1067973

+1

我要在黑暗中進行狂野刺殺,並猜測1,Text是一個字符串,2,PhoneData是一個Phone,3,字符串和Phones不是同一個東西。它希望你寫一點代碼將文本轉換爲手機。 –

+0

此外,現在您的原始問題已得到解答,您可以點贊所有幫助您的答案。它讓每個人都開心。 –

8

顯然,類型CustomerFiles.Phone(或其包含類型CustomerFiles,如果它是一種類型而不是名稱空間)不具有public的可見性。由於返回類型創建的屬性是公共的,類型本身需要public爲好。

+1

否則,調用phone屬性的那個不知道CustomerFiles.Phone是什麼,因爲它不是公開的。 –

+0

感謝您的解釋,這非常好 – user1067973

0

它告訴你,這些類型是私人或保護,但你想用公共的getter和setter表面他們。使公共類

+0

感謝隊友我明白這一點,因爲你 – user1067973

+0

隨意投我了;) –

0

確保

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

是公開的。

+0

好解釋 – user1067973

2

首先改變所有類型的公共避免訪問性問題。 其次你就不能更改

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

+0

我解決了它,非常感謝:) – user1067973

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

}