嘗試這個:static class Program{ /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); var f = new Form1(); f.Mode = false; Application.Run(f); bool playerMode = f.Mode; }}和:public partial class Form1 : Form{ public Form1() { InitializeComponent(); } public bool Mode = false; private void button1_Click(object sender, EventArgs e) { this.Mode = true; this.Close(); } private void button2_Click(object sender, EventArgs e) { this.Mode = false; this.Close(); }}這對我bool playerMode根據(jù)我單擊的按鈕進行設(shè)置很好用。
1 回答

qq_遁去的一_1
TA貢獻1725條經(jīng)驗 獲得超8個贊
這里的問題是 protobuf-net 通過附加數(shù)據(jù)來反序列化列表(等)數(shù)據(jù)。
解決方案是將列表初始化從 ctor 移動到具有設(shè)置屬性 SkipConstructor=true 的構(gòu)造函數(shù)。
[ProtoContract(SkipConstructor=true)]
public class Data
{
[ProtoMember(1)]
public bool[] Flags;
public Data()
{
Falgs = new bool[3] { true, true, true }
}
}
- 1 回答
- 0 關(guān)注
- 199 瀏覽
添加回答
舉報
0/150
提交
取消