#region
Hashtable和HashSet
Hashtable ff = new Hashtable(); //创建哈希表
ff.Add("33", "66"); //往哈希表里添加键值对
ff.Contains("33"); //判断哈希表里是否包含该键
ff.ContainsKey("33");
ff.ContainsValue("33");
string name = (string)ff["33"].ToString(); //取哈希表里指定键的值
//ff.Remove("33"); //删除哈希表里指定键的键值对
//ff.Clear();//移除哈希表里所有的键值对
foreach (string item in ff.Keys) //遍历所有的键
{
string str1 = (string)ff[item];
}
IDictionaryEnumerator en = ff.GetEnumerator(); //遍历哈希表所有的键,读出相应的值
while (en.MoveNext())
{
string str1 = en.Value.ToString();
string str2 = en.Key.ToString();
}
HashSet<string> cc = new HashSet<string>();
cc.Add("11");
cc.Add("22");
cc.Add("33");
cc.Add("44");
string[] aestr = new string[6];
cc.CopyTo(aestr);
cc.GetEnumerator().MoveNext();//?
#endregion
#region List,Dictionary
//List<string> listfx = new List<string>();//可
List<string> listfx = new List<string>(aestr);
listfx.Add("11");
listfx.Add("11");
listfx.Add("22");
listfx.Add("33");
listfx.Add("44");
listfx.Add("55");
listfx.Add("55");
listfx.Add("66");
//取值
string listk1 = listfx[0];
string listk2 = listfx.Find(x => { return x.Length > 1; });
string listk3 = listfx.FindLast(x => { return x.Length > 1; });
List<string> listk4 = new List<string>();
listk4 = listfx.FindAll(x => 1 == 1);
List<string> listk6 = listfx.GetRange(2, 4);
string[] listk5 = listfx.ToArray();
//迭代器
foreach (var item in listfx)
{
string str1 = item;
listfx.GetEnumerator().MoveNext();
string str2 = item;
listfx.GetEnumerator().MoveNext();
string str3 = item;
listfx.GetEnumerator().Dispose();
string str4 = item;
}
//List<string>.Enumerator kkk3 = listfx.GetEnumerator();//?
//判断元素是否全部符合条件 TrueForAll
bool isbbb = listfx.TrueForAll(x =>
{
bool isff = false;
if (!string.IsNullOrEmpty(x))
{
isff = x.Length > 1;
}
return isff;
});
常用
//listfx.AddRange();
//listfx.Clear();
//listfx.Contains();
//CopyTo();
//Exists();
//FindIndex();
//ForEach();
//IndexOf();
//InsertRange();
//Remove();
//RemoveAll();
//RemoveAt();
//RemoveRange();
Dictionary<string, string> dicff = new Dictionary<string, string>();
dicff.Add("k1", "1");
dicff.Add("k2", "1");
dicff.Add("k3", "2");
dicff.Add("k4", "3");
dicff.Add("k5", "4");
#endregion
Hashtable ff = new Hashtable(); //创建哈希表
ff.Add("33", "66"); //往哈希表里添加键值对
ff.Contains("33"); //判断哈希表里是否包含该键
ff.ContainsKey("33");
ff.ContainsValue("33");
string name = (string)ff["33"].ToString(); //取哈希表里指定键的值
//ff.Remove("33"); //删除哈希表里指定键的键值对
//ff.Clear();//移除哈希表里所有的键值对
foreach (string item in ff.Keys) //遍历所有的键
{
string str1 = (string)ff[item];
}
IDictionaryEnumerator en = ff.GetEnumerator(); //遍历哈希表所有的键,读出相应的值
while (en.MoveNext())
{
string str1 = en.Value.ToString();
string str2 = en.Key.ToString();
}
HashSet<string> cc = new HashSet<string>();
cc.Add("11");
cc.Add("22");
cc.Add("33");
cc.Add("44");
string[] aestr = new string[6];
cc.CopyTo(aestr);
cc.GetEnumerator().MoveNext();//?
#endregion
#region List,Dictionary
//List<string> listfx = new List<string>();//可
List<string> listfx = new List<string>(aestr);
listfx.Add("11");
listfx.Add("11");
listfx.Add("22");
listfx.Add("33");
listfx.Add("44");
listfx.Add("55");
listfx.Add("55");
listfx.Add("66");
//取值
string listk1 = listfx[0];
string listk2 = listfx.Find(x => { return x.Length > 1; });
string listk3 = listfx.FindLast(x => { return x.Length > 1; });
List<string> listk4 = new List<string>();
listk4 = listfx.FindAll(x => 1 == 1);
List<string> listk6 = listfx.GetRange(2, 4);
string[] listk5 = listfx.ToArray();
//迭代器
foreach (var item in listfx)
{
string str1 = item;
listfx.GetEnumerator().MoveNext();
string str2 = item;
listfx.GetEnumerator().MoveNext();
string str3 = item;
listfx.GetEnumerator().Dispose();
string str4 = item;
}
//List<string>.Enumerator kkk3 = listfx.GetEnumerator();//?
//判断元素是否全部符合条件 TrueForAll
bool isbbb = listfx.TrueForAll(x =>
{
bool isff = false;
if (!string.IsNullOrEmpty(x))
{
isff = x.Length > 1;
}
return isff;
});
常用
//listfx.AddRange();
//listfx.Clear();
//listfx.Contains();
//CopyTo();
//Exists();
//FindIndex();
//ForEach();
//IndexOf();
//InsertRange();
//Remove();
//RemoveAll();
//RemoveAt();
//RemoveRange();
Dictionary<string, string> dicff = new Dictionary<string, string>();
dicff.Add("k1", "1");
dicff.Add("k2", "1");
dicff.Add("k3", "2");
dicff.Add("k4", "3");
dicff.Add("k5", "4");
#endregion