我看了另一個類似於這個問題,但不明白他們做了什麼來解決這個問題。類型初始化異常c#
我只是傳遞一個值到一個公共靜態INT:
namespace ModNote
{
public partial class homeScreen : Form
{
public homeScreen()
{
InitializeComponent();
}
private void gamemodButton_Click(object sender, EventArgs e)
{
backgroundProgram.moduleNumber = 1;
this.Hide();
moduleScreen showForm = new moduleScreen();
showForm.Show();
}
而這正是這個變量初始化
namespace ModNote
{
#region // Setting up Variables
public class backgroundProgram
{
public static int moduleNumber;
}
#endregion
}
,並在這裏的錯誤的圖片:http://puu.sh/opETJ/fb8152d164.png
謝謝。
編輯:初始化字符串數組導致此錯誤,此數組正在初始化的任何問題? (moduleArray)
namespace ModNote
{
#region // Setting up Variables
public class backgroundProgram
{
public static int moduleNumber;
public static string[] noteArray;
public static string[] moduleArray = new string[7]
{ File.ReadAllText(@"ModulesFile\CGP1005M.txt"),
File.ReadAllText(@"ModulesFile\CMP1005M.txt"),
File.ReadAllText(@"ModulesFile\CMP1123M.txt"),
File.ReadAllText(@"ModulesFile\CMP1124M.txt"),
File.ReadAllText(@"ModulesFile\CMP1125M.txt"),
File.ReadAllText(@"ModulesFile\CMP1127M.txt"),
File.ReadAllText(@"ModulesFile\CMP1129M.txt")
};
}
#endregion
}
該異常通常指示靜態初始化程序或構造函數中的異常。既然你沒有表現出我認爲實際問題在別的地方。 –
我剛剛意識到它不起作用,當我初始化我的數組 – Durell
如果你不能解決它可以編輯這個問題,並投票重新打開它)或創建一個新的。 –