我仍然是java的新手,我想知道如何将地图(或 HashMaps )置于枚举之内同时还将键和值放入地图中。这甚至可能吗?如果没有,有人可以解释原因吗? 谢谢!
答案 0 :(得分:1)
Java作为EnumMap类,你可以。示例如下所示。
public partial class Form1 : Form
{
private FormSettings frmSettings1 = new FormSettings();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.textBox1.Text = frmSettings1.FormText;
}
private void button1_Click(object sender, EventArgs e)
{
frmSettings1.FormText = textBox1.Text;
this.Close();
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
frmSettings1.Save();
}
}
//Application settings wrapper class
sealed class FormSettings : ApplicationSettingsBase
{
[UserScopedSettingAttribute()]
public String FormText
{
get { return (String)this["FormText"]; }
set { this["FormText"] = value; }
}
}