本文整理汇总了C#中HashedSet类的典型用法代码示例。如果您正苦于以下问题:C# HashedSet类的具体用法?C# HashedSet怎么用?C# HashedSet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HashedSet类属于命名空间,在下文中一共展示了HashedSet类的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 set = new HashedSet<int>();
for (int i = 1; i < 11; i++)
{
for (int j = 0; j < 3; j++)
{
set.Add(i);
}
}
System.Console.WriteLine(set);
System.Console.WriteLine(set.Count);
var otherSet = new HashedSet<int>();
for (int i = 5; i < 16; i++)
{
otherSet.Add(i);
}
System.Console.WriteLine(otherSet);
System.Console.WriteLine(otherSet.Count);
System.Console.WriteLine(set.IntersectsWith(otherSet));
System.Console.WriteLine(set.Union(otherSet));
}
示例3: GetClassEntries
/// <summary>
/// Returns a collection of <see cref="ClassEntry" /> containing
/// information about all classes in this stream.
/// </summary>
/// <param name="document">A validated <see cref="XmlDocument"/> representing
/// a mapping file.</param>
public static ICollection GetClassEntries(XmlDocument document)
{
XmlNamespaceManager nsmgr = HbmBinder.BuildNamespaceManager(document.NameTable);
// Since the document is validated, no error checking is done in this method.
HashedSet classEntries = new HashedSet();
XmlNode root = document.DocumentElement;
string assembly = XmlHelper.GetAttributeValue(root, "assembly");
string @namespace = XmlHelper.GetAttributeValue(root, "namespace");
XmlNodeList classNodes = document.SelectNodes(
"//" + HbmConstants.nsClass +
"|//" + HbmConstants.nsSubclass +
"|//" + HbmConstants.nsJoinedSubclass +
"|//" + HbmConstants.nsUnionSubclass,
nsmgr
);
foreach (XmlNode classNode in classNodes)
{
string name = XmlHelper.GetAttributeValue(classNode, "name");
string extends = XmlHelper.GetAttributeValue(classNode, "extends");
ClassEntry ce = new ClassEntry(extends, name, assembly, @namespace);
classEntries.Add(ce);
}
return classEntries;
}
示例4: 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));
}
示例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()
{
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);
}
}
示例7: Task
public Task()
{
CreatedDate = ModifiedDate = DateTimeHelper.Now;
Id = Guid.NewGuid();
_title = "";
Links = new HashedSet<Link>();
}
示例8: ProductQuotation
public ProductQuotation(Quotation quotation, string name, string group)
{
Quotation = quotation;
Name = name;
Group = group;
Editions = new HashedSet<EditionQuotation>();
}
示例9: Main
static void Main(string[] args)
{
ISessionFactory sf = CreateSessionFactory();
using(ISession s = sf.OpenSession()) {
using(ITransaction t = s.BeginTransaction()) {
ISet<T3> t3 = new HashedSet<T3>() {
new T3() {str="a"},
new T3() {str="b"},
new T3() {str="c"}
};
foreach(T3 tt3 in t3)
s.Save(tt3);
T1 t1 = new T1() {
str = "t1",
t3 = t3
};
T2 t2 = new T2() {
str = "t2",
t3 = t3
};
s.Save(t1);
s.Save(t2);
t.Commit();
//IList<T1> k = s.QueryOver<T1>().List();
//Console.WriteLine(k[0].id);
//s.Delete(k[0]);
//t.Commit();
}
}
Console.ReadKey();
}
示例10: InitializerShouldCreateEmptyHashedSet
public void InitializerShouldCreateEmptyHashedSet()
{
var set = new HashedSet<int>();
int expected = 0;
Assert.AreEqual(expected, set.Count);
}
示例11: TestFindWithInvalidKey
public void TestFindWithInvalidKey()
{
var table = new HashedSet<string>();
table.Add("Pesho");
var value = table.Find("Peho");
}
示例12: TestFindShouldProperlyWork
public void TestFindShouldProperlyWork()
{
var table = new HashedSet<string>();
table.Add("Pesho");
Assert.AreEqual(true, table.Find("Pesho"));
}
示例13: 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);
}
示例14: AddShouldNotThrowExceptionWhenTheSameKeyIsAlreadyPresent
public void AddShouldNotThrowExceptionWhenTheSameKeyIsAlreadyPresent()
{
var hashedset = new HashedSet<string>();
hashedset.Add("gosho");
hashedset.Add("gosho");
}
示例15: Distinct
public IEnumerable Distinct(IEnumerable source)
{
var s = new HashedSet();
foreach (object item in source)
s.Add(item);
return s;
}