2014-10-18 64 views
1

這是我第一次至少使用Stackoverflow作爲提問者,而英文不是我的母語,所以請對不起我的英文。錯誤1不一致的可訪問性:

我得到這個錯誤

可訪問性不一致:字段類型 'System.Collections.Generic.List' 比場 'Agenda.Form1.listaPersonas'

我竟然發現少了訪問它在其他問題,但所有的答案說,參數必須公開,這是我不明白的東西。我仍然是一名學生,並且我瞭解到該領域的知名度必須是私密的,訪問者必須公開。無論如何,我試圖把它們私人化,但我仍然有同樣的問題。

這裏是我的代碼:

namespace Agenda 
{ 
    public partial class Form1 : Form 
    { 
     public List<Persona> listaPersonas = new List<Persona>(); 

     public Form1() 
     { 
      InitializeComponent(); 
     } 
    } 

    class Persona 
    { 
     private string nombre; 
     private string apellidos; 
     private string telefono; 
     private DateTime fechaNac; 

     public Persona(string nom, string ape, string tel, DateTime fecNac) { 
      this.nombre = nom; 
      this.apellidos = ape; 
      this.telefono = tel; 
      this.fechaNac = fecNac; 
     } 
    } 
} 

回答

1
class Persona 

指類只是內部的。 你必須讓它public,使其可以訪問到你的其他代碼

只是公衆關鍵字添加到它:

public class Persona 
+0

絕非類是私有的只有類是內部沒有私人 – 2014-10-18 10:06:43

+0

沒錯真正。鍵入的速度超過思維有時suxx;) – MichaC 2014-10-18 10:11:01

0

你必須添加

public class Persona 

    { 

您的構造函數定義public創建類的實例,將不可能作爲默認修飾符是internal當沒有修飾符適用

From MSDN

Classes and structs that are declared directly within a namespace (in other words, that are not nested within other classes or structs) can be either public or internal. Internal is the default if no access modifier is specified.

相關問題