2014-01-29 42 views
0

我已經瀏覽了這裏的幾篇文章,並且沒有找到我找到的解決方案。我嘗試從窗體a傳遞一個對象到窗體b,當你點擊一個菜單項時,它給了我錯誤:不一致性可訪問性:參數類型

錯誤1不一致的可訪問性:參數類型'WindowsFormsApplication1.character'比方法'WindowsFormsApplication1.CharBuilder.CharBuilder(WindowsFormsApplication1.character)'

這裏爲發送形式:

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.Windows.Forms; 

namespace WindowsFormsApplication1 
{ 
    public partial class GVL4 : Form 
    { 
     public GVL4() 
     { 
      InitializeComponent(); 
     } 

     public void mNewGame_Click(object sender, EventArgs e) 
     { 
      character MyCharacter = new character(); 

      MyCharacter.SetIsNew(); 

      CharBuilder NewCharacter = new CharBuilder(MyCharacter); 

      NewCharacter.Show(); 
     } 
    } 
} 

和接收形式:

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.Windows.Forms; 

namespace WindowsFormsApplication1 
{ 
    public partial class CharBuilder : Form 
    { 
     character Char = new character(); 

     public CharBuilder() 
     { 
      InitializeComponent(); 
     } 

     //Overloaded Constructor 
     public CharBuilder(character cChar) 
     { 
      Char = cChar; 
     } 

     private void txtSect_TextChanged(object sender, EventArgs e) 
     { 

     } 

     private void btnSaveID_Click(object sender, EventArgs e) 
     { 
      if (Char.IsNew()) 
      { 
       Char.SaveCharIdentity(txtCharName.Text, txtClan.Text, txtSect.Text, txtNature.Text, txtDemeanor.Text, txtTitle.Text, txtCoterie.Text, txtSire.Text, txtPlayerName.Text, txtCharacterID.Text, txtStatus.Text, Convert.ToInt32(txtUnspentXP.Text), Convert.ToInt32(txtEarnedXP.Text), Convert.ToInt32(txtGeneration.Text), Convert.ToInt32(txtBloodPool.Text), cbxNPC.Checked); 
      } 

      txtTestBox.Text = Char.ToString(); 
     } 

     public void CharBuilder_Load(object sender, EventArgs e) 
     { 

     } 

    } 
} 

的錯誤是在重載(公共CharBuilder(字符CCHAR))

+0

發佈定義您的角色類的代碼,這是問題的可能來源。 –

回答

0

這意味着你character類比public少,比如您的公共方法。您需要確保訪問修飾符相同。我不確定你的班級設計,所以不知道最佳路線是什麼,但如果沒有人將你的代碼作爲圖書館使用,只需要公開角色類。

+0

BAH。當然。我正在看錶格代碼而不是我的角色班。它沒有明確的公開。感謝您的幫助! –

0

你沒有發佈你的角色類的代碼,但它聽起來像這個類被標記爲public以外的東西,這就是你看到這個錯誤的原因。將您的character類的聲明更改爲public,它將起作用。

1

character類在哪裏定義?我嫌犯這是GVL4裏面的私人課程?什麼錯誤是告訴你的是,即使你要傳遞的character一個實例CharBuilderCharBuilder實際上不知道有什麼一個對象character任何方式。它接收一個對象,但它沒有定義該對象的類。

確保character類對這兩種形式都是已知的。我想應該只是在項目中的其他地方定義的一個單獨的類,可能是公開的或內部的,而不是任何特定形式的內部。

側注意:您的代碼非常難以閱讀,因爲您沒有遵循C#約定。類/類型名稱應該以大寫字母開頭,局部變量名稱應該以小寫字母開頭。

+0

幾個小時前我剛剛開始在C#中編寫代碼,這些約定我一無所知。謝謝你的信息,但我會確保查找它們並嘗試合併它們。 –

相關問題