本文整理汇总了C#中Set.First方法的典型用法代码示例。如果您正苦于以下问题:C# Set.First方法的具体用法?C# Set.First怎么用?C# Set.First使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Set
的用法示例。
在下文中一共展示了Set.First方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ShouldAdd
public void ShouldAdd()
{
var collection = new Set<string>();
collection.Add("1");
collection.Add("2");
Assert.AreEqual(2, collection.Count);
Assert.AreEqual("1", collection.First());
Assert.AreEqual("2", collection.Last());
}
示例2: ShouldRemove
public void ShouldRemove()
{
var collection = new Set<string>();
collection.Add("1");
collection.Add("2");
collection.Remove("1");
collection.Remove(null);
Assert.AreEqual(1, collection.Count);
Assert.AreEqual("2", collection.First());
}
示例3: ShouldNotAddNulls
public void ShouldNotAddNulls()
{
var collection = new Set<string>();
collection.Add(null);
collection.Add("1");
collection.Add(null);
collection.Add(null);
Assert.AreEqual(1, collection.Count);
Assert.AreEqual("1", collection.First());
}
示例4: FixRange
internal override BoolExpr<DomainConstraint<BoolLiteral, Constant>> FixRange(Set<Constant> range, MemberDomainMap memberDomainMap)
{
Debug.Assert(range.Count == 1, "For BoolLiterals, there should be precisely one value - true or false");
var scalar = (ScalarConstant)range.First();
var expr = GetDomainBoolExpression(memberDomainMap);
if ((bool)scalar.Value == false)
{
// The range of the variable was "inverted". Return a NOT of
// the expression
expr = new NotExpr<DomainConstraint<BoolLiteral, Constant>>(expr);
}
return expr;
}
示例5: ReadClusters
void ReadClusters() {
XmlRead();
while (TokenIs(GeometryToken.Cluster))
ReadCluster();
FleshOutClusters();
var rootClusterSet = new Set<Cluster>();
foreach (var cluster in stringToClusters.Values.Select(c => c.Cluster))
if (cluster.ClusterParents == null || !cluster.ClusterParents.Any())
rootClusterSet.Insert(cluster);
if (rootClusterSet.Count == 1)
_graph.RootCluster = rootClusterSet.First();
else {
_graph.RootCluster.AddRangeOfCluster(rootClusterSet);
}
if (!XmlReader.IsStartElement())
ReadEndElement();
}
示例6: GetCommonAncestorsAbovePassport
Set<Shape> GetCommonAncestorsAbovePassport(Set<Shape> passport) {
if (!passport.Any()) return new Set<Shape>();
var ret = ancestorSets[passport.First()];
foreach (var shape in passport.Skip(1))
ret *= ancestorSets[shape];
return ret;
}
示例7: Main
static void Main()
{
Console.Write("Enter number of elements to read: ");
string line = Console.ReadLine();
int N;
while (!(int.TryParse(line, out N) && N > 0))
{
Console.Write("Please enter a positive integer: ");
line = Console.ReadLine();
}
Console.WriteLine();
int[] numbers = new int[N];
for (int idx = 0; idx < N; idx++)
{
Console.Write("Enter number {0}: ", idx + 1);
line = Console.ReadLine();
while (!(int.TryParse(line, out numbers[idx])))
{
Console.Write("Please enter an integer: ");
line = Console.ReadLine();
}
Console.WriteLine();
}
Console.Write("{" + String.Join(", ", numbers) + "} -> ");
int majMinOccurs = N / 2 + 1;
/*Solution 1 - Predicates*/
List<int> numbersList = numbers.ToList<int>();
Set<int> numbersSet = new Set<int>();
numbersSet.AddMany(numbersList);
try
{
int majorant = numbersSet.First(setElement => (numbersList.FindAll(
listElement => listElement == setElement).Count >= majMinOccurs));
Console.WriteLine(majorant);
}
catch
{
Console.WriteLine("No majorant!");
}
Console.WriteLine();
/*Solution 2 - Dictionary*/
//Dictionary<int, int> occurrences = new Dictionary<int, int>();
//for (int i = 0; i < N; i++)
//{
// if (!occurrences.Keys.Contains(numbers[i]))
// {
// occurrences.Add(numbers[i], 1);
// }
// else
// {
// occurrences[numbers[i]]++;
// }
//}
//bool hasMajorant = false;
//foreach (KeyValuePair<int, int> pair in occurrences)
//{
// if (pair.Value >= majMinOccurs)
// {
// Console.WriteLine(pair.Key);
// hasMajorant = true;
// break;
// }
//}
//if (!hasMajorant)
//{
// Console.WriteLine("No majorant!");
//}
//Console.WriteLine();
}
示例8: FleshOutSubgraphs
void FleshOutSubgraphs() {
foreach (var subgraphTemlate in subgraphTable.Values) {
var subgraph = subgraphTemlate.Subgraph;
foreach (var id in subgraphTemlate.SubgraphIdList)
subgraph.AddSubgraph(subgraphTable[id].Subgraph);
foreach (var id in subgraphTemlate.NodeIdList)
subgraph.AddNode(this.graph.FindNode(id));
}
var rootSubgraphSet = new Set<Subgraph>();
foreach (var subgraph in subgraphTable.Values.Select(c => c.Subgraph))
if (subgraph.ParentSubgraph == null) {
rootSubgraphSet.Insert(subgraph);
graph.RootSubgraph.AddSubgraph(subgraph);
}
if (rootSubgraphSet.Count == 1)
graph.RootSubgraph = rootSubgraphSet.First();
else
foreach (var subgraph in rootSubgraphSet)
graph.RootSubgraph.AddSubgraph(subgraph);
}