本文整理汇总了C#中Set.Add方法的典型用法代码示例。如果您正苦于以下问题:C# Set.Add方法的具体用法?C# Set.Add怎么用?C# Set.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Set
的用法示例。
在下文中一共展示了Set.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SecondAdd
public void SecondAdd()
{
Set<int> set = new Set<int>();
set.Add(1);
set.Add(2);
Assert.AreEqual(2, set.Count);
}
示例2: AddWithDelegatePositiveTest
public void AddWithDelegatePositiveTest()
{
ISet<string> sets = new Set<string>();
sets.Add("item1");
sets.Add("item22", (i,j) => i.Length == j.Length);
Assert.AreEqual(2, sets.Count);
}
示例3: BFS
/*************************/
// Selecting initial vertices
/*************************/
// Returns a vertex on the last level of a Breadth-first search (BFS)
public static int BFS(Graph graph, int init)
{
// BFS working queue
Queue<int> queue = new Queue<int>();
// Vertices that have already been visited
Set<int> visited = new Set<int>();
// Initial vertex is given as input
visited.Add(init);
queue.Enqueue(init);
int current = init;
// While there is still a vertex in the queue...
while (queue.Count > 0)
{
//... select the first vertex and process it
current = queue.Dequeue();
foreach (int w in graph.OpenNeighborhood(current))
{
// Enqueue all neighbors that have not been processed yet
if (!visited.Contains(w))
{
visited.Add(w);
queue.Enqueue(w);
}
}
}
// This is the last vertex that has been processed, thus a vertex that is on the last level of the BFS search
return current;
}
示例4: Main
static void Main()
{
var setOne = new Set<int>();
setOne.Add(5);
setOne.Add(5);
setOne.Add(5);
setOne.Add(5);
setOne.Add(5);
setOne.Add(5);
setOne.Add(5);
setOne.Add(5);
setOne.Add(5);
setOne.Add(6);
var setTwo = new Set<int>();
setTwo.Add(5);
setTwo.Add(10);
Console.WriteLine(setOne);
Console.WriteLine(setTwo);
var union = setOne.Union(setTwo);
Console.WriteLine();
Console.WriteLine(union);
var intersect = setOne.Intersect(setTwo);
Console.WriteLine(intersect);
}
示例5: Main
public static void Main()
{
var set1 = new Set<string>();
var set2 = new Set<string>();
set1.Add("one");
set1.Add("two");
set1.Add("three");
set2.Add("three");
set2.Add("four");
Console.WriteLine(set1);
Console.WriteLine(set2);
Console.WriteLine(set1.Intersect(set2));
Console.WriteLine(set2.Intersect(set1));
Console.WriteLine(set1.Union(set2));
Console.WriteLine(set2.Union(set1));
set1.Remove("five");
set1.Remove("two");
Console.WriteLine(set1);
Console.WriteLine(set1.Find("one"));
Console.WriteLine(set1.Find("two"));
Console.WriteLine(set1.Count);
}
示例6: GenerateParens2
Set<string> GenerateParens2(int remaining)
{
Set<string> set = new Set<string>();
if (remaining == 0)
{
set.Add("");
}
else
{
Set<string> prev = GenerateParens2(remaining - 1);
foreach (string str in prev)
{
for (int i = 0; i < str.Length; i++)
{
if (str[i] == '(')
{
string s = InsertInside(str, i);
/* Add s to set if it is not already in there. Note:
* Set automatically checks for duplicates before
* adding, so an explicit check is not necessary. */
set.Add(s);
}
}
set.Add("()" + str);
}
}
return set;
}
示例7: ToSet
internal static ISet ToSet(this IFullTextSearchResult result, String matchVar, String scoreVar)
{
Set s = new Set();
if (matchVar != null) s.Add(matchVar, result.Node);
if (scoreVar != null) s.Add(scoreVar, result.Score.ToLiteral(_factory));
return s;
}
示例8: Evaluate
/// <summary>
/// Evaluates the Select Distinct Graphs optimisation
/// </summary>
/// <param name="context">Evaluation Context</param>
/// <returns></returns>
public BaseMultiset Evaluate(SparqlEvaluationContext context)
{
context.OutputMultiset = new Multiset();
String var;
if (context.Query != null)
{
var = context.Query.Variables.First(v => v.IsResultVariable).Name;
}
else
{
var = this._graphVar;
}
foreach (Uri graphUri in context.Data.GraphUris)
{
Set s = new Set();
if (graphUri == null)
{
s.Add(var, null);
}
else
{
s.Add(var, new UriNode(null, graphUri));
}
context.OutputMultiset.Add(s);
}
return context.OutputMultiset;
}
示例9: Main
static void Main(string[] args)
{
Set a = new Set();
a.Add(1);
a.Add(2);
a.Add(3);
Console.WriteLine("a : " + a);
Set b = new Set();
b.Add(2);
b.Add(3);
Console.WriteLine("b : " + b);
Set c = new Set();
c = a.Union(b);
Console.WriteLine("a.Union(b) : " + c);
c = a.Intersection(b);
Console.WriteLine("a.Intersection(b) : " + c);
c = a.Difference(b);
Console.WriteLine("a.Difference(b) : " + c);
bool flag;
flag = a.IsSubsetOf(b);
Console.WriteLine("a.IsSubsetOf(b) : " + flag);
flag = b.IsSubsetOf(a);
Console.WriteLine("b.IsSubsetOf(a) : " + flag);
Console.Read();
}
示例10: AddPositiveTest
public void AddPositiveTest()
{
ISet<string> sets = new Set<string>();
sets.Add("item1");
sets.Add("item2");
Assert.AreEqual(2, sets.Count);
}
示例11: ShouldClear
public void ShouldClear()
{
var collection = new Set<string>();
collection.Add("1");
collection.Add("2");
collection.Clear();
Assert.AreEqual(0, collection.Count);
}
示例12: TestIfAddAddsACorrectAmount
public void TestIfAddAddsACorrectAmount()
{
var set = new Set<int>();
set.Add(5);
set.Add(6);
Assert.AreEqual(2, set.Count);
}
示例13: RemoveTest
public void RemoveTest()
{
Set<int> set = new Set<int>();
set.Add(1);
set.Add(2);
set.Remove(1);
Assert.IsFalse(set.Contains(1));
Assert.IsTrue(set.Contains(2));
}
示例14: TestDel
public void TestDel()
{
var mySet = new Set<int>();
mySet.Add(1);
mySet.Add(2);
mySet.Del(2);
Assert.IsTrue(mySet.IsExist(1));
Assert.IsTrue(!mySet.IsExist(2));
}
示例15: AddArrayToNonEmptySet
public void AddArrayToNonEmptySet() {
var set = new Set<int>();
set.Add(11);
set.Add(22);
set.Add(new [] { 33, 44, 55 });
Assert.Equals(5, set.Count);
Assert.True(set.Contains(11));
Assert.True(set.Contains(44));
}