本文整理汇总了C#中HashSet.RemoveWhere方法的典型用法代码示例。如果您正苦于以下问题:C# HashSet.RemoveWhere方法的具体用法?C# HashSet.RemoveWhere怎么用?C# HashSet.RemoveWhere使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HashSet
的用法示例。
在下文中一共展示了HashSet.RemoveWhere方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
/* The words of the dictionary this evil hangman example works with are supplied in the linear array below.
* For a more sophisticated implementation loading from an external file is obviously possible, but the idea here
* was to provide a simple solution to the problem, so beginner programmers could understand how they could solve
* it themselves.
*/
string[] dict = {"bakalava", "balamata", "balerina", "balirina", "baniceta", "kalotina", "kolibata", "korubata"};
HashSet<string> words = new HashSet<string>(dict);
char[] seq = {'l', 'r', 'i', 'o', 'e', 'n', 'm', 'k', 'v', 't', 'b', 'c', 'd', 'f', 'g', 'h', 'j', 'p', 'r', 's', 'u', 'w', 'x', 'y', 'z'};
HashSet<char> toGuess = new HashSet<char>(seq);
Random rand = new Random();
Console.WriteLine("Pick a word: (1-" + words.Count + ")");
int ind = int.Parse(Console.ReadLine());
Console.WriteLine("The word you chose is " + answer + ". Let's see whether the computer can guess it...");
answer = dict[ind - 1];
guessed.Add(answer[0]);
guessed.Add(answer[answer.Length - 1]);
while (words.Count != 1)
{
words.RemoveWhere(Remover);
PrintGuessed(guessed);
Console.WriteLine(string.Join(", ", words));
guessed.Add(toGuess.First());
toGuess.Remove(toGuess.First());
}
Console.WriteLine("The word is: " + words.First());
Console.ReadLine();
}
示例2: GetFreePointsInRange
private static HashSet<Point> GetFreePointsInRange(Point pivotPoint)
{
// The 8 points below are the 8 possible moves of a horse if is not near the end of a board
Point topRight = new Point(pivotPoint.Row + 2, pivotPoint.Col + 1);
Point topLeft = new Point(pivotPoint.Row + 2, pivotPoint.Col - 1);
Point rightUpper = new Point(pivotPoint.Row + 1, pivotPoint.Col + 2);
Point rightLower = new Point(pivotPoint.Row - 1, pivotPoint.Col + 2);
Point leftUpper = new Point(pivotPoint.Row + 1, pivotPoint.Col - 2);
Point leftLower = new Point(pivotPoint.Row - 1, pivotPoint.Col - 2);
Point bottomRight = new Point(pivotPoint.Row - 2, pivotPoint.Col + 1);
Point bottomLeft = new Point(pivotPoint.Row - 2, pivotPoint.Col - 1);
HashSet<Point> freePointsInRange = new HashSet<Point>()
{
topRight, topLeft,
rightUpper, rightLower,
leftUpper, leftLower,
bottomRight, bottomLeft
};
// Removes each point that is out of the board or that has been visited
freePointsInRange.RemoveWhere(x => x.Col < 0 ||
x.Row < 0 ||
x.Row >= matrix.GetLength(0) ||
x.Col >= matrix.GetLength(1) ||
matrix[x.Row, x.Col] != 0);
return freePointsInRange;
}
示例3: FilterEntities
public void FilterEntities(BattleEntity sourceEntity, HashSet<BattleEntity> entities)
{
switch(mTargetParam) {
case AISkillRule.ConditionTarget.ENEMY:
entities.RemoveWhere(FilterEnemy);
break;
case AISkillRule.ConditionTarget.PC:
entities.RemoveWhere(FilterPC);
break;
case AISkillRule.ConditionTarget.SELF:
entities.RemoveWhere(delegate(BattleEntity obj) {
return sourceEntity != obj;
});
break;
}
}
示例4: LadderLength
public int LadderLength(string start, string end, string[] dict)
{
HashSet<string> hset = new HashSet<string>(dict);
HashSet<string> currentStarts = new HashSet<string>() { start };
int answer = 1;
while (true)
{
hset.RemoveWhere(v => currentStarts.Contains(v));
HashSet<string> nextStarts = new HashSet<string>();
foreach (var starting in currentStarts)
{
if (starting == end)
{
return answer;
}
GetValidMoves(starting, hset).ToList().ForEach(n => nextStarts.Add(n));
}
if (nextStarts.Count > 0)
{
answer++;
currentStarts = nextStarts;
}
else
{
return 0;
}
}
}
示例5: Circulars
public static int Circulars(int range)
{
int count = 0;
HashSet<int> primes = new HashSet<int>();
primes.UnionWith(Primes.primeRange(range));
HashSet<string> stringprimes = new HashSet<string>();
stringprimes.UnionWith(primes.Select<int, string>(x => x.ToString()));
stringprimes.RemoveWhere(x => x.Contains('2') || x.Contains('4') || x.Contains('6') || x.Contains('8') || x.Contains('0'));
foreach (string number in stringprimes) {
string varnumber = number.Substring(0);
bool allPrime = true;
for (int i = 0; i < number.Length; i++) {
char c = varnumber.First<char>();
varnumber += c;
varnumber = varnumber.Remove(0, 1);
if (!primes.Contains(int.Parse(varnumber))) {
//Console.WriteLine(number);
allPrime = false;
break;
}
}
if (allPrime == true) {
count++;
}
allPrime = true;
}
return count + 1;
}
示例6: Execute
public void Execute()
{
var mask = new NodeMask();
mask.Label = "Cycles";
mask.IsShowMask = true;
try
{
if (!myPresentation.Graph.Nodes.Any())
{
return;
}
var unvisited = new HashSet<Node>(myPresentation.Graph.Nodes);
unvisited.RemoveWhere(n => n.In.Count == 0 || n.Out.Count == 0);
while (unvisited.Count > 0)
{
var current = unvisited.First();
unvisited.Remove(current);
foreach (var node in FindCycles(unvisited, current, new HashSet<Node> { current }))
{
mask.Set(node);
}
}
}
finally
{
var module = myPresentation.GetModule<INodeMaskModule>();
module.Push(mask);
}
}
示例7: Shrink
public static HashSet<Triangle> Shrink(HashSet<Triangle> set)
{
HashSet<Triangle> Shrunk = new HashSet<Triangle>(set);
Shrunk.RemoveWhere(t => t.Neighbors.Any(i => !set.Contains(i)));
return Shrunk;
}
示例8: ToString
public override string ToString()
{
if (OperationTypes == null || OperationTypes.Count == 0) return null;
var uniqueTypes = new HashSet<Type>();
var uniqueTypeNames = new List<string>();
foreach (var type in OperationTypes)
{
foreach (var assemblyType in type.Assembly.GetTypes())
{
if (assemblyType.GetCustomAttributes(typeof(DataContractAttribute), false).Length > 0)
{
var baseTypeWithSameName = XsdMetadata.GetBaseTypeWithTheSameName(assemblyType);
if (uniqueTypeNames.Contains(baseTypeWithSameName.GetOperationName()))
{
log.WarnFormat("Skipping duplicate type with existing name '{0}'", baseTypeWithSameName.GetOperationName());
}
uniqueTypes.Add(baseTypeWithSameName);
}
}
}
uniqueTypes.RemoveWhere(x => x.IsGenericTypeDefinition());
this.OperationTypes = uniqueTypes;
var schemaSet = XsdUtils.GetXmlSchemaSet(OperationTypes);
var xsd = XsdUtils.GetXsd(schemaSet);
var filteredXsd = Filter(xsd);
return filteredXsd;
}
示例9: Filter
/// <summary>
/// Removes all methods from the set that are not compatible to the signature of the <pramref name="signature" />.
/// </summary>
/// <param name="methods">The set of methods that should be filtered.</param>
/// <param name="delegateType">The signature the methods must be compatible to.</param>
public static void Filter(HashSet<IMethodSymbol> methods, INamedTypeSymbol delegateType)
{
Requires.NotNull(methods, nameof(methods));
Requires.NotNull(delegateType, nameof(delegateType));
Requires.That(delegateType.TypeKind == TypeKind.Delegate, "Expected a delegate type.");
methods.RemoveWhere(port => !port.IsSignatureCompatibleTo(delegateType.DelegateInvokeMethod));
}
示例10: Resolve
/// <inheritdoc />
public IEnumerable<TagHelperDescriptor> Resolve([NotNull] TagHelperDescriptorResolutionContext context)
{
var resolvedDescriptors = new HashSet<TagHelperDescriptor>(TagHelperDescriptorComparer.Default);
// tagHelperPrefix directives do not affect which TagHelperDescriptors are added or removed from the final
// list, need to remove them.
var actionableDirectiveDescriptors = context.DirectiveDescriptors.Where(
directive => directive.DirectiveType != TagHelperDirectiveType.TagHelperPrefix);
foreach (var directiveDescriptor in actionableDirectiveDescriptors)
{
try
{
var lookupInfo = GetLookupInfo(directiveDescriptor, context.ErrorSink);
// Could not resolve the lookup info.
if (lookupInfo == null)
{
return Enumerable.Empty<TagHelperDescriptor>();
}
if (directiveDescriptor.DirectiveType == TagHelperDirectiveType.RemoveTagHelper)
{
resolvedDescriptors.RemoveWhere(descriptor => MatchesLookupInfo(descriptor, lookupInfo));
}
else if (directiveDescriptor.DirectiveType == TagHelperDirectiveType.AddTagHelper)
{
var descriptors = ResolveDescriptorsInAssembly(
lookupInfo.AssemblyName,
directiveDescriptor.Location,
context.ErrorSink);
// Only use descriptors that match our lookup info
descriptors = descriptors.Where(descriptor => MatchesLookupInfo(descriptor, lookupInfo));
resolvedDescriptors.UnionWith(descriptors);
}
}
catch (Exception ex)
{
string directiveName;
_directiveNames.TryGetValue(directiveDescriptor.DirectiveType, out directiveName);
Debug.Assert(!string.IsNullOrEmpty(directiveName));
context.ErrorSink.OnError(
directiveDescriptor.Location,
Resources.FormatTagHelperDescriptorResolver_EncounteredUnexpectedError(
"@" + directiveName,
directiveDescriptor.DirectiveText,
ex.Message));
}
}
var prefixedDescriptors = PrefixDescriptors(context, resolvedDescriptors);
return prefixedDescriptors;
}
示例11: Run
public override void Run(string[] args)
{
var filenames = string.Empty;
var options = new OptionSet() { { "f=|files=", "Merges the specified split files.", f => filenames = f } };
options.Parse(args);
if (string.IsNullOrWhiteSpace(filenames))
{
throw new OptionSetException(options);
}
var splitFiles = new HashSet<string>(Directory.EnumerateFiles(@".\", filenames));
var workFiles = new List<string>(splitFiles.Take(splitFiles.Count - Take >= Take ? Take : splitFiles.Count));
splitFiles.RemoveWhere(s => workFiles.Contains(s));
int splitId = 0;
bool firstRun = true;
var createdFiles = new HashSet<string>();
while (workFiles.Count > 1 || firstRun)
{
int written = 0;
var multiQueue = new MultiQueue(workFiles);
using (var stream = Utils.FindFirstSplitFile("merge", ref splitId))
{
createdFiles.Add(stream.Name);
Console.WriteLine("Merging {0} into {1}", string.Join(",", from f in workFiles
select Path.GetFileName(f)),
Path.GetFileName(stream.Name));
foreach (var item in multiQueue.Merge())
{
stream.Write(item.ToGuid().ToByteArray(), 0, 16);
if (++written % 1000000 == 0)
{
Console.WriteLine("Written {0} lines", written);
}
}
}
Console.WriteLine("Written {0} lines", written);
Console.WriteLine("Excluded {0} duplicates.", multiQueue.Duplicates);
if (!firstRun)
{
workFiles.ForEach(f => File.Delete(f));
}
workFiles = new List<string>(splitFiles.Take(splitFiles.Count - Take >= Take ? Take : splitFiles.Count));
splitFiles.RemoveWhere(s => workFiles.Contains(s));
if (workFiles.Count < Take)
{
splitFiles = createdFiles;
createdFiles = new HashSet<string>();
workFiles = new List<string>(splitFiles.Take(Take));
splitFiles.RemoveWhere(s => workFiles.Contains(s));
firstRun = false;
}
}
}
示例12: GenerateFourDigitTriangleNumbers
HashSet<int> GenerateFourDigitTriangleNumbers()
{
var triangleNumbers = new HashSet<int>();
for (int i = 1; i < 1000; i++) {
triangleNumbers.Add(i * (i + 1) / 2);
}
triangleNumbers.RemoveWhere(tn => tn / 1000 >= 1 && tn / 1000 < 10);
return triangleNumbers;
}
示例13: GenerateFourDigitSquareNumbers
HashSet<int> GenerateFourDigitSquareNumbers()
{
var squareNumbers = new HashSet<int>();
for (int i = 1; i < 100; i++) {
squareNumbers.Add(i * i);
}
squareNumbers.RemoveWhere(sn => sn / 1000 >= 1 && sn / 1000 < 10);
return squareNumbers;
}
示例14: FilterEntities
public void FilterEntities(BattleEntity sourceEntity, HashSet<BattleEntity> entities)
{
switch(mHpCondition) {
case AISkillRule.HitPointCondition.HP_DEAD:
entities.RemoveWhere(delegate(BattleEntity obj) {
return obj.character.curHP > 0;
});
break;
case AISkillRule.HitPointCondition.HP_GT:
entities.RemoveWhere(delegate(BattleEntity obj) {
return obj.character.curHP / obj.character.maxHP <= mHpPercValue;
});
break;
case AISkillRule.HitPointCondition.HP_LT:
entities.RemoveWhere(delegate(BattleEntity obj) {
return obj.character.curHP / obj.character.maxHP >= mHpPercValue;
});
break;
// highest, just find the max
case AISkillRule.HitPointCondition.HP_HIGHEST:
float maxHP = -1;
foreach(BattleEntity entity in entities) {
maxHP = Mathf.Max(maxHP, entity.character.curHP);
}
entities.RemoveWhere(delegate(BattleEntity obj) {
return obj.character.curHP != maxHP;
});
break;
case AISkillRule.HitPointCondition.HP_LOWEST:
float minHP = 9999999;
foreach(BattleEntity entity in entities) {
// we want to make sure we dont count dead people
minHP = Mathf.Max(1, Mathf.Min(minHP, entity.character.curHP));
}
entities.RemoveWhere(delegate(BattleEntity obj) {
return obj.character.curHP != minHP;
});
break;
}
}
示例15: FilterEntities
public void FilterEntities(BattleEntity sourceEntity, HashSet<BattleEntity> entities)
{
switch(mHpCondition) {
case AISkillRule.ResourceCondition.RES_EMPTY:
entities.RemoveWhere(delegate(BattleEntity obj) {
return obj.character.curResource > 0;
});
break;
case AISkillRule.ResourceCondition.RES_GT:
entities.RemoveWhere(delegate(BattleEntity obj) {
return obj.character.curResource / obj.character.maxResource <= mHpPercValue;
});
break;
case AISkillRule.ResourceCondition.RES_LT:
entities.RemoveWhere(delegate(BattleEntity obj) {
return obj.character.curResource / obj.character.maxResource >= mHpPercValue;
});
break;
// highest, just find the max
case AISkillRule.ResourceCondition.RES_HIGHEST:
float maxResource = -1;
foreach(BattleEntity entity in entities) {
maxResource = Mathf.Max(maxResource, entity.character.curResource);
}
entities.RemoveWhere(delegate(BattleEntity obj) {
return obj.character.curResource != maxResource;
});
break;
case AISkillRule.ResourceCondition.RES_LOWEST:
float minResource = 9999999;
foreach(BattleEntity entity in entities) {
// we want to make sure we dont count dead people
minResource = Mathf.Min(minResource, entity.character.curResource);
}
entities.RemoveWhere(delegate(BattleEntity obj) {
return obj.character.curResource != minResource;
});
break;
}
}