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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
List<string> a = new List<string>(); //0,1,3,4,4.2
string zilch = "zero";
string first = "one";
string second = "two";
string third = "three";
string fourth = "4.2";
string twopointtwo = "2.2";
a.Add(zilch); //0,1,2,3
a.Add(first);
a.Add(second);
a.Add(third);
if (a.Contains("three")) //0,1,2,3,4
{
a.Add("four");
}
a.RemoveAt(2);//去掉2 0,1,3,4
if (a.IndexOf("four") != 4) //加4.2 0,1,3,4,4.2
{
a.Add(fourth);
}
if (a.Contains("two")) //没有2啊!,不加入2.2
{
a.Add(twopointtwo);
}
printL(a);
}
public void printL(List<string> a)
{
string result = "";
foreach (string element in a)
{
result += "\n" + element;
}
// MessageBox.Show("result");
MessageBox.Show(result); //注意单双引号的区分
}
}
}