本文整理汇总了C#中HashedSet.Add方法的典型用法代码示例。如果您正苦于以下问题:C# HashedSet.Add方法的具体用法?C# HashedSet.Add怎么用?C# HashedSet.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HashedSet
的用法示例。
在下文中一共展示了HashedSet.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
public static void Main(string[] args)
{
HashedSet<string> students = new HashedSet<string>();
students.Add("Pesho");
students.Add("Pesho");
students.Add("Gosho");
students.Remove("Gosho");
students.Add("Misho");
students.Add("Ivan");
Console.WriteLine("Student count: {0}", students.Count);
HashedSet<string> users = new HashedSet<string>();
users.Add("Mariq");
users.Add("Pesho");
users.Add("Misho");
HashedSet<string> intersection = students.Intersect(users);
Console.WriteLine("Intersection:");
foreach (var name in intersection)
{
Console.WriteLine(name);
}
HashedSet<string> union = students.Union(users);
Console.WriteLine("Union: ");
foreach (var name in union)
{
Console.WriteLine(name);
}
}
示例2: Main
public static void Main()
{
var firstSet = new HashedSet<string>();
var secondSet = new HashedSet<string>();
firstSet.Add("Pesho");
firstSet.Add("Gosho");
firstSet.Add("Tosho");
secondSet.Add("Ivan");
secondSet.Add("Petkan");
secondSet.Add("Dragan");
Console.WriteLine(firstSet);
Console.WriteLine(secondSet);
Console.WriteLine(firstSet.Intersect(secondSet));
Console.WriteLine(secondSet.Intersect(firstSet));
Console.WriteLine(firstSet.Union(secondSet));
Console.WriteLine(secondSet.Union(firstSet));
firstSet.Remove("Pesho");
firstSet.Remove("Tosho");
Console.WriteLine(firstSet);
Console.WriteLine(firstSet.Find("Tosho"));
Console.WriteLine(firstSet.Find("Gosho"));
Console.WriteLine(firstSet.Count);
}
示例3: Union_Test
public void Union_Test()
{
HashedSet<int> set = new HashedSet<int>();
HashedSet<int> otherSet = new HashedSet<int>();
set.Add(1);
set.Add(2);
set.Add(3);
otherSet.Add(3);
otherSet.Add(4);
otherSet.Add(5);
set.Union(otherSet);
StringBuilder actual = new StringBuilder();
foreach (var item in set)
{
actual.Append(item + " ");
}
string expected = "1 2 3 4 5 ";
Assert.AreEqual(expected, actual.ToString());
}
示例4: Main
static void Main()
{
HashedSet<string> myBestFriends = new HashedSet<string>();
myBestFriends.Add("Ivan");
myBestFriends.Add("Daniel");
myBestFriends.Add("Cecilia");
Console.WriteLine(myBestFriends.Count);
myBestFriends.Remove("Cecilia");
Console.WriteLine(myBestFriends.Count);
HashedSet<string> yourBestFriends = new HashedSet<string>();
yourBestFriends.Add("Petar");
yourBestFriends.Add("Daniel");
yourBestFriends.Add("Monika");
HashedSet<string> allBestFriends = myBestFriends.Union(yourBestFriends);
Console.WriteLine("All best friends: ");
foreach (var item in allBestFriends.setOfData)
{
Console.WriteLine("{0}", item.Value);
}
HashedSet<string> mutualBestFriends = myBestFriends.Intersect(yourBestFriends);
Console.WriteLine("Mutual best friends: ");
foreach (var item in mutualBestFriends.setOfData)
{
Console.WriteLine("{0}", item.Value);
}
}
示例5: test
public void test()
{
using (ISession s = OpenSession())
using (ITransaction tx = s.BeginTransaction())
{
Person person = new Person("1");
person.Name = "John Doe";
var set = new HashedSet<object>();
set.Add("555-1234");
set.Add("555-4321");
person.Properties.Add("Phones", set);
s.Save(person);
tx.Commit();
}
using (ISession s = OpenSession())
using (ITransaction tx = s.BeginTransaction())
{
Person person = (Person)s.CreateCriteria(typeof(Person)).UniqueResult();
Assert.AreEqual("1", person.ID);
Assert.AreEqual("John Doe", person.Name);
Assert.AreEqual(1, person.Properties.Count);
Assert.That(person.Properties["Phones"], Is.InstanceOf<ISet<object>>());
Assert.IsTrue(((ISet<object>) person.Properties["Phones"]).Contains("555-1234"));
Assert.IsTrue(((ISet<object>) person.Properties["Phones"]).Contains("555-4321"));
}
}
示例6: Main
static void Main()
{
var mySet = new HashedSet<string>();
mySet.Add("string");
mySet.Add("str");
//mySet.Add(null);
mySet.Add("strength");
mySet.Add("string");
//var strength = mySet.Find("strength");
//Console.WriteLine(strength);
//var isStringRemoved = mySet.Remove("string");
//Console.WriteLine(isStringRemoved);
var mySecondSet = new HashedSet<string>();
mySecondSet.Add("strength");
mySecondSet.Add("dexterity");
mySecondSet.Add("intelligence");
mySet.Union(mySecondSet);
//mySet.Intersect(mySecondSet);
foreach (var item in mySet)
{
Console.WriteLine(item);
}
}
示例7: Main
public static void Main()
{
HashedSet<float> firstSet = new HashedSet<float>();
firstSet.Add(1f);
firstSet.Add(1.4f);
firstSet.Add(1.7f);
firstSet.Add(2f);
firstSet.Add(2.2f);
firstSet.Remove(1.7f);
Console.WriteLine(firstSet.Find(1f));
Console.WriteLine(firstSet.Count);
HashedSet<float> secondSet = new HashedSet<float>();
secondSet.Add(1f);
secondSet.Add(2f);
secondSet.Add(3f);
secondSet.Add(5f);
HashedSet<float> thirdSet = new HashedSet<float>();
thirdSet.Add(1f);
thirdSet.Add(2f);
thirdSet.Add(3f);
thirdSet.Add(5f);
secondSet.Union(firstSet);
thirdSet.Intersect(firstSet);
firstSet.Clear();
}
示例8: Main
static void Main()
{
var set = new HashedSet<int>();
set.Add(5);
set.Add(3);
set.Add(-4);
set.Add(12);
set.Add(0);
set.Add(-50);
set.Add(10);
Console.WriteLine("Set contains 12 -> {0}", set.Find(12));
Console.WriteLine("Set contains 13 -> {0}", set.Find(13));
set.Remove(10);
Console.WriteLine("Removed 10\nSet contains 10 -> {0}", set.Find(10));
Console.WriteLine("Set contains {0} items", set.Count);
Console.WriteLine("Set 1: {0}", set);
var anotherSet = new HashedSet<int>();
anotherSet.Add(-4);
anotherSet.Add(15);
anotherSet.Add(0);
anotherSet.Add(-122);
anotherSet.Add(35);
Console.WriteLine("Set 2: {0}", anotherSet);
set.Union(anotherSet);
Console.WriteLine("Set after union: {0}", set);
set.Intersect(anotherSet);
Console.WriteLine("Set after intersect: {0}", set);
set.Clear();
Console.WriteLine("Set contains {0} items after clear", set.Count);
}
示例9: AddShouldNotThrowExceptionWhenTheSameKeyIsAlreadyPresent
public void AddShouldNotThrowExceptionWhenTheSameKeyIsAlreadyPresent()
{
var hashedset = new HashedSet<string>();
hashedset.Add("gosho");
hashedset.Add("gosho");
}
示例10: Main
/* 5 Implement the data structure "set" in a class HashedSet<T> using your class HashTable<K,T>
* to hold the elements. Implement all standard set operations like Add(T), Find(T), Remove(T),
* Count, Clear(), union and intersect.
* */
static void Main(string[] args)
{
var set = new HashedSet<int>();
Debug.Assert(set.Count == 0);
Debug.Assert(!set.Find(1));
set.Add(1);
Debug.Assert(set.Count == 1);
Debug.Assert(set.Find(1));
set.Add(2);
Debug.Assert(set.Count == 2);
Debug.Assert(set.Find(2));
set.Add(1);
Debug.Assert(set.Count == 2);
Debug.Assert(set.Find(1));
set.Remove(1);
Debug.Assert(set.Count == 1);
Debug.Assert(!set.Find(1));
Debug.Assert(set.Find(2));
var set1 = new HashedSet<int> { 1, 2, 3, 4, 5, 6 }.Intersect(new HashedSet<int> { 2, 4, 6, 8, 10 });
Debug.Assert(set1.SameContents(new[] { 2, 4, 6 }, i => i));
var set2 = new HashedSet<int> { 1, 2, 3, 4, 5, 6 }.Union(new HashedSet<int> { 2, 4, 6, 8, 10 });
Debug.Assert(set2.SameContents(new[] { 1, 2, 3, 4, 5, 6, 8, 10 }, i => i));
}
示例11: TestAddMethod
public void TestAddMethod()
{
var hashedSet = new HashedSet<int>();
Assert.IsTrue(hashedSet.Add(1));
Assert.IsTrue(hashedSet.Add(2));
Assert.IsFalse(hashedSet.Add(2));
Assert.AreEqual(2, hashedSet.Count);
}
示例12: BuildSearcher
public static IndexSearcher BuildSearcher(ISearchFactoryImplementor searchFactory,
out ISet<System.Type> classesAndSubclasses,
params System.Type[] classes)
{
IDictionary<System.Type, DocumentBuilder> builders = searchFactory.DocumentBuilders;
ISet<IDirectoryProvider> directories = new HashedSet<IDirectoryProvider>();
if (classes == null || classes.Length == 0)
{
// no class means all classes
foreach (DocumentBuilder builder in builders.Values)
{
foreach (IDirectoryProvider provider in builder.DirectoryProvidersSelectionStrategy.GetDirectoryProvidersForAllShards())
{
directories.Add(provider);
}
}
// Give them back an empty set
classesAndSubclasses = null;
}
else
{
ISet<System.Type> involvedClasses = new HashedSet<System.Type>();
involvedClasses.AddAll(classes);
foreach (System.Type clazz in classes)
{
DocumentBuilder builder;
builders.TryGetValue(clazz, out builder);
if (builder != null)
{
involvedClasses.AddAll(builder.MappedSubclasses);
}
}
foreach (System.Type clazz in involvedClasses)
{
DocumentBuilder builder;
builders.TryGetValue(clazz, out builder);
// TODO should we rather choose a polymorphic path and allow non mapped entities
if (builder == null)
{
throw new HibernateException("Not a mapped entity: " + clazz);
}
foreach (IDirectoryProvider provider in builder.DirectoryProvidersSelectionStrategy.GetDirectoryProvidersForAllShards())
{
directories.Add(provider);
}
}
classesAndSubclasses = involvedClasses;
}
IDirectoryProvider[] directoryProviders = new List<IDirectoryProvider>(directories).ToArray();
return new IndexSearcher(searchFactory.ReaderProvider.OpenReader(directoryProviders));
}
示例13: IntersectShouldReturnCollectionWithRepeatValues
public void IntersectShouldReturnCollectionWithRepeatValues()
{
HashedSet<string> set = new HashedSet<string>();
set.Add("value 1");
set.Add("Pesho");
var resultSet = hashedSet.Intersect(set);
Assert.AreEqual(1, resultSet.Count());
}
示例14: ShouldCorrectlyAddAllValues
public void ShouldCorrectlyAddAllValues()
{
var set = new HashedSet<int>();
set.Add(1);
set.Add(3);
set.Add(5);
set.Add(7);
set.Add(9);
Assert.AreEqual(5, set.Count);
}
示例15: ShouldNotAddDuplicateValues
public void ShouldNotAddDuplicateValues()
{
var set = new HashedSet<int>();
set.Add(1);
set.Add(1);
set.Add(1);
set.Add(1);
set.Add(1);
Assert.AreEqual(1, set.Count);
}