Thaxll'ssillyia
Captain
- Registriert
- Dez. 2007
- Beiträge
- 3.501
Hi Community!
Ich habe ein Problem mit einer Dictionary mit Key string und Value struct.
So sieht mein Code aus:
Problem ist, wenn ich einen 2. Eintrag hinzufüge, erhält der erste auch diesen Wert (Programm zum Testen im Anhang).
Was mache ich falsch? Vielen Dank für Hilfe!
Gruß Thax
Ich habe ein Problem mit einer Dictionary mit Key string und Value struct.
So sieht mein Code aus:
Code:
public partial class Form1 : Form
{
struct Channel
{
static string titel;
static string admin;
static string pw;
public Channel(bool SetEmpty)
{
if (SetEmpty == true)
{
titel = null;
admin = null;
pw = null;
}
}
public static string[] Refresh()
{
string[] Out = new string[3];
Out[0] = titel;
Out[1] = admin;
Out[2] = pw;
return Out;
}
public string Titel
{
get { return titel; }
set { titel = value; }
}
public string Admin
{
get { return admin; }
set { admin = value; }
}
public string PW
{
get { return pw; }
set { pw = value; }
}
}
static Dictionary<string, Channel> ChannelList = new Dictionary<string, Channel>();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string ChannelName = textBox1.Text;
Channel I = new Channel(true);
I.Titel = textBox2.Text;
I.Admin = textBox3.Text;
I.PW = textBox4.Text;
ChannelList.Add(ChannelName, I);
listBox1.Items.Clear();
listBox1.Items.AddRange(Channel.Refresh());
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
textBox4.Clear();
RefreshListView();
}
void RefreshListView()
{
listView1.Items.Clear();
foreach (string ChannelName in ChannelList.Keys)
{
Channel I = ChannelList[ChannelName];
listView1.Items.Add(ChannelName);
listView1.Items[listView1.Items.Count - 1].SubItems.Add(I.Titel);
listView1.Items[listView1.Items.Count - 1].SubItems.Add(I.Admin);
listView1.Items[listView1.Items.Count - 1].SubItems.Add(I.PW);
}
}
}
Problem ist, wenn ich einen 2. Eintrag hinzufüge, erhält der erste auch diesen Wert (Programm zum Testen im Anhang).
Was mache ich falsch? Vielen Dank für Hilfe!
Gruß Thax