我不知道“static List<user> AllUserList = new List<user>(); ”添进数据 然后怎么把这个数据给移除了。请大家帮忙。详细代码如下
user.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace WF_Server
{
public class user
{
public string userName { get; set; }
public string _ipport { get; set; }
public user()
{
this.userName = "";
this._ipport = "";
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace WF_Server
{
public partial class Form_Server : Form
{
static List<user> AllUserList = new List<user>();
public Form_Server()
{
InitializeComponent();
} private void panel1_Paint(object sender, PaintEventArgs e)
{ } private void button1_Click(object sender, EventArgs e) //增加 {
string stra = textBox1.Text;
user temp = new user();
temp.userName = stra; temp._ipport = stra; AllUserList.Add(temp);
} private void button3_Click(object sender, EventArgs e) //显示
{
listBox1.Items.Clear();
for (int i = 0; i < AllUserList.Count; i++)
{
listBox1.Items.Add(AllUserList[i].userName.ToString());
}
} private void button2_Click(object sender, EventArgs e) //移除
{
string stra = textBox1.Text;
user temp = new user();
temp.userName = stra; temp._ipport = stra; 我这里这么写始终不能移除当时添入的数据,该怎么更改才可以,希望详细指点。谢谢了
AllUserList.Remove(temp);
} }
}
user.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace WF_Server
{
public class user
{
public string userName { get; set; }
public string _ipport { get; set; }
public user()
{
this.userName = "";
this._ipport = "";
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace WF_Server
{
public partial class Form_Server : Form
{
static List<user> AllUserList = new List<user>();
public Form_Server()
{
InitializeComponent();
} private void panel1_Paint(object sender, PaintEventArgs e)
{ } private void button1_Click(object sender, EventArgs e) //增加 {
string stra = textBox1.Text;
user temp = new user();
temp.userName = stra; temp._ipport = stra; AllUserList.Add(temp);
} private void button3_Click(object sender, EventArgs e) //显示
{
listBox1.Items.Clear();
for (int i = 0; i < AllUserList.Count; i++)
{
listBox1.Items.Add(AllUserList[i].userName.ToString());
}
} private void button2_Click(object sender, EventArgs e) //移除
{
string stra = textBox1.Text;
user temp = new user();
temp.userName = stra; temp._ipport = stra; 我这里这么写始终不能移除当时添入的数据,该怎么更改才可以,希望详细指点。谢谢了
AllUserList.Remove(temp);
} }
}
解决方案 »
- 关于access数据库更新的问题
- C#里的sql语句如何得到昨天,今天?在线等
- tcp通信中使用SslStream和数据字证书的问题?郁闷求急救
- C#中对打印机的操作问题
- 咨询:现在的程序开发对数据掌握的要求
- Command与ExecuteReader的问题
- c# 的form 中如何知道当前汉文输入法是否打开?
- 为什么昨天还能打开项目文件,今天就“无法从WEB服务器获取项目文件。急急急
- C#如何向word中动态添加书签
- 大家好,小妹我初来贵地,请问大哥哥们怎么才能学好C#!
- 怎样用c# 打开cad文件进行预览、实现 缩放、移动 ;
- 大家说说VS自带的打包工具和InstallShield比较,有什么区别
{
return (u.userName == textBox1.Text && u._ipport == textBox1.Text);
}
protected void Page_Load(object sender, EventArgs e)
{
int index = AllUserList.FindIndex(issame);
if (index >= 0)
{
AllUserList.RemoveAt(index);
}
}
for (int i = 0; i < AllUserList.Count; i++)
{
listBox1.Items.Add(AllUserList[i].userName.ToString()); 找到在移除啊
}