本文整理汇总了C#中HashSet.Find方法的典型用法代码示例。如果您正苦于以下问题:C# HashSet.Find方法的具体用法?C# HashSet.Find怎么用?C# HashSet.Find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HashSet
的用法示例。
在下文中一共展示了HashSet.Find方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ClearShouldRemoveElement
public void ClearShouldRemoveElement()
{
var hashtable = new HashSet<int>();
hashtable.Add(10);
Assert.IsTrue(hashtable.Find(10));
hashtable.Clear();
Assert.IsFalse(hashtable.Find(10));
}
示例2: HashSetShouldFindElementsCorrectly
public void HashSetShouldFindElementsCorrectly()
{
var set = new HashSet<int>();
set.Add(0);
set.Add(1);
set.Add(2);
set.Add(3);
Assert.IsTrue(set.Find(0));
Assert.IsTrue(set.Find(1));
Assert.IsTrue(set.Find(2));
Assert.IsTrue(set.Find(3));
Assert.IsFalse(set.Find(4));
}
示例3: FindShouldReturnTrueForAddedElement
public void FindShouldReturnTrueForAddedElement()
{
var hashtable = new HashSet<string>();
hashtable.Add("aaa");
Assert.IsTrue(hashtable.Find("aaa"));
}
示例4: HashSetShouldRemoveElementCorrectly
public void HashSetShouldRemoveElementCorrectly()
{
var set = new HashSet<int>();
set.Add(0);
set.Remove(0);
Assert.IsFalse(set.Find(0));
Assert.AreEqual(0, set.Count);
}
示例5: Main
static void Main(string[] args)
{
try
{
HashSet<int> set = new HashSet<int>();
set.Add(13);
set.Add(14);
set.Add(15);
set.Add(16);
set.Add(17);
Console.WriteLine(set.Find(14));
Console.WriteLine("Count: {0}", set.Count);
set.Remove(14);
Console.WriteLine("Count: {0}", set.Count);
Console.WriteLine(set.Find(14));
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
示例6: Main
public static void Main()
{
try
{
HashSet<int> hashSet = new HashSet<int>();
hashSet.Add(1);
hashSet.Add(5);
hashSet.Add(2);
hashSet.Add(33);
Console.WriteLine("Count is : {0}", hashSet.Count);
hashSet.Remove(2);
Console.WriteLine("Count is : {0}", hashSet.Count);
Console.WriteLine(hashSet.Find(5));
Console.WriteLine(hashSet.Contains(5));
int[] numArray = new int[] { 5, 11, 33 };
int[] array = numArray;
hashSet.UnionWith(array);
Console.WriteLine("Count is : {0}", hashSet.Count);
int[] numArray1 = new int[] { 5, 11, 22 };
int[] array2 = numArray1;
hashSet.Intersect(array2);
Console.WriteLine("Count is : {0}", hashSet.Count);
hashSet.Clear();
Console.WriteLine("Count is : {0}", hashSet.Count);
Console.WriteLine(hashSet.Find(5));
}
catch (ArgumentException aex)
{
Console.WriteLine(aex.Message);
}
}
示例7: Main
static void Main(string[] args)
{
HashSet<string> hashSet = new HashSet<string>();
hashSet.Add("ooo");
hashSet.Add("qqq");
hashSet.Add("ppp");
hashSet.Add("iii");
foreach (var item in hashSet.Items)
{
Console.WriteLine(item);
}
hashSet.Remove("iii");
Console.WriteLine("\nCount after removal: {0}", hashSet.Count);
Console.WriteLine();
Console.WriteLine(hashSet.Find("ppp"));
HashSet<string> secondHashSet = new HashSet<string>();
secondHashSet.Add("www");
secondHashSet.Add("qqq");
secondHashSet.Add("yyy");
secondHashSet.Add("ooo");
Console.WriteLine("\nUnion: ");
HashSet<string> union = hashSet.Union(secondHashSet);
foreach (var item in union.Items)
{
Console.WriteLine(item);
}
Console.WriteLine("\nIntersection: ");
HashSet<string> intersection = hashSet.Intersect(secondHashSet);
foreach (var item in intersection.Items)
{
Console.WriteLine(item);
}
}
示例8: Main
static void Main(string[] args)
{
IHashSet<int> sampleOne = new HashSet<int>();
sampleOne.Add(1);
sampleOne.Add(1);
sampleOne.Add(2);
sampleOne.Add(3);
sampleOne.Add(4);
sampleOne.Add(5);
sampleOne.Add(6);
sampleOne.Add(7);
sampleOne.Add(8);
sampleOne.Add(9);
IHashSet<int> sampleTwo = new HashSet<int>();
sampleTwo.Add(1);
sampleTwo.Add(2);
sampleTwo.Add(9);
sampleTwo.Add(100);
Console.WriteLine("sampleOne:");
foreach (var item in sampleOne)
{
Console.WriteLine(item);
}
Console.WriteLine("sampleTwo:");
foreach (var item in sampleTwo)
{
Console.WriteLine(item);
}
IHashSet<int> intersected = sampleOne.Intersect(sampleTwo);
Console.WriteLine("Intesected of sampleOne and sampleTwo:");
foreach (var item in intersected)
{
Console.WriteLine(item);
}
IHashSet<int> union = sampleOne.Union(sampleTwo);
Console.WriteLine("Union of sampleOne and sampleTwo:");
foreach (var item in union)
{
Console.WriteLine(item);
}
int founded = sampleOne.Find(1);
Console.WriteLine("Look for '1':" + founded);
Console.WriteLine("Count:" + sampleOne.Count);
sampleOne.Remove(3);
sampleOne.Clear();
Console.WriteLine("Count after clear:" + sampleOne.Count);
}
示例9: FindShouldReturnFalseIfKeyIsNotAdded
public void FindShouldReturnFalseIfKeyIsNotAdded()
{
var hashtable = new HashSet<string>();
Assert.IsFalse(hashtable.Find("aaa"));
}
示例10: RemoveShouldWorkProperly
public void RemoveShouldWorkProperly()
{
var hashtable = new HashSet<int>();
hashtable.Add(10);
Assert.IsTrue(hashtable.Find(10));
hashtable.Remove(10);
Assert.IsFalse(hashtable.Find(10));
}