本文整理汇总了C#中KeyValuePair.Any方法的典型用法代码示例。如果您正苦于以下问题:C# KeyValuePair.Any方法的具体用法?C# KeyValuePair.Any怎么用?C# KeyValuePair.Any使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KeyValuePair
的用法示例。
在下文中一共展示了KeyValuePair.Any方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoTestsMatchFilterRequest
private static bool DoTestsMatchFilterRequest(string[] testTags, KeyValuePair<string, string>[] filterTags)
{
//If no tags were requested, then then it is a match
if (!filterTags.Any())
{
return true;
}
var includeTags = filterTags.Where(t => t.Value.Equals("true", StringComparison.OrdinalIgnoreCase))
.Select(t => t.Key)
.ToArray();
var excludeTags = filterTags.Where(t => t.Value.Equals("false", StringComparison.OrdinalIgnoreCase))
.Select(t => t.Key)
.ToArray();
return !excludeTags.Intersect(testTags, StringComparer.OrdinalIgnoreCase).Any() &&
includeTags.Intersect(testTags, StringComparer.OrdinalIgnoreCase).Count() == includeTags.Count();
}
示例2: GenerateIntervals
private static IEnumerable<Interval> GenerateIntervals(DateTime start, KeyValuePair<DateTime, float>[] staffingPercentages)
{
if (!staffingPercentages.Any())
throw new ApplicationException("Staffing percentages required");
var lastEnd = start;
foreach (var workforcePercentage in staffingPercentages)
{
var interval = new Interval()
{
Start = lastEnd,
End = workforcePercentage.Key,
StaffingPercentage = workforcePercentage.Value
};
lastEnd = interval.End;
yield return interval;
}
}
示例3: XmlEscape
// Taken from https://stackoverflow.com/questions/1132494/string-escape-into-xml
public static string XmlEscape(string escaped)
{
var replacements = new KeyValuePair<string, string>[]
{
new KeyValuePair<string,string>("&", "&"),
new KeyValuePair<string,string>("\"", """),
new KeyValuePair<string,string>("'", "'"),
new KeyValuePair<string,string>("<", "<"),
new KeyValuePair<string,string>(">", ">"),
};
foreach (var pair in replacements)
foreach (var index in escaped.IndexesOf(pair.Key, 0).Reverse())
if (!replacements.Any(other => string.Compare(other.Value, 0, escaped, index, other.Value.Length, StringComparison.Ordinal) == 0))
{
escaped = escaped.Substring(0, index) + pair.Value + escaped.Substring(index + 1, escaped.Length - index - 1);
}
return escaped;
}
示例4: SerializeNavigatorPopularRoomsNews
/// <summary>
/// Serializes the navigator popular rooms news.
/// </summary>
/// <param name="reply">The reply.</param>
/// <param name="rooms">The rooms.</param>
/// <param name="category">The category.</param>
/// <param name="direct">if set to <c>true</c> [direct].</param>
public void SerializeNavigatorPopularRoomsNews(ref ServerMessage reply, KeyValuePair<RoomData, uint>[] rooms,
int category, bool direct)
{
if (rooms == null || !rooms.Any())
{
reply.AppendInteger(0);
return;
}
List<RoomData> roomsCategory = new List<RoomData>();
foreach (KeyValuePair<RoomData, uint> pair in rooms.Where(pair => pair.Key.Category.Equals(category)))
{
roomsCategory.Add(pair.Key);
if (roomsCategory.Count == (direct ? 40 : 8)) break;
}
reply.AppendInteger(roomsCategory.Count);
foreach (RoomData data in roomsCategory) data.Serialize(reply, false);
}
示例5: BuilCommandCall
private static string BuilCommandCall(string fullName, VariableParameter[] givenParameters, KeyValuePair<string, string>[] defaultedValues)
{
var result = new StringBuilder();
result.Append(fullName);
foreach (var parameter in givenParameters)
{
result.Append(" ");
result.Append(parameter.Name);
result.Append("=\"");
result.Append(parameter.Value);
result.Append("\"");
}
if (defaultedValues.Any())
{
result.Append("(with defaults:");
foreach (var pair in defaultedValues)
{
result.Append(" ");
result.Append(pair.Key);
result.Append("=\"");
result.Append(pair.Value);
result.Append("\"");
}
result.Append(")");
}
return result.ToString();
}
示例6: CopyTo_IndexZero_ValuesCopied
public void CopyTo_IndexZero_ValuesCopied()
{
Trie<string, char, int> trie = new Trie<string, char, int>();
trie.Add("key1", 5);
trie.Add("key2", 6);
KeyValuePair<string, int>[] vals = new KeyValuePair<string, int>[4];
trie.CopyTo(vals, 0);
Assert.IsTrue(vals.Any(k => k.Key == "key1" && k.Value == 5));
Assert.IsTrue(vals.Any(k => k.Key == "key2" && k.Value == 6));
Assert.AreEqual(0, vals[2].Value);
Assert.AreEqual(0, vals[3].Value);
}
示例7: EvidenceRealization
/// <summary>
/// Realiza todas las realizaciones de una evidencia estocastica
/// </summary>
/// <param name="evidence"></param>
/// <param name="realization"></param>
/// <param name="pos"></param>
/// <returns></returns>
static IEnumerable<Tuple<KeyValuePair<BayesianNode, int>[],double>> EvidenceRealization(Evidence evidence, KeyValuePair<BayesianNode, int>[] realization, int pos,double probability=1.0)
{
if (pos == realization.Length)
{
if(realization.Any(x=>x.Value>=0))
yield return new Tuple<KeyValuePair<BayesianNode, int>[], double>(realization,probability);
yield break;
}
//en cada paso recursivo se escoge un nodo para su seleccion de estado
//por cada probabilidad de estar en un estado de el nodo en la posicion pos
bool outofevidence = true;
for (int i = 0; i < evidence.EvidenceValues[pos].Length; i++)
{
if (evidence.EvidenceValues[pos][i] > 0)
{
realization[pos] = new KeyValuePair<BayesianNode, int>(realization[pos].Key, i);
outofevidence = false;
var p = probability*evidence.EvidenceValues[pos][i];
foreach (var item in EvidenceRealization(evidence, realization, pos + 1,p))
yield return item;
}
}
//si no esta en la evidencia entonces relization[pos]=bayesiannode,-1
if(outofevidence)
foreach (var item in EvidenceRealization(evidence, realization, pos + 1,probability))
yield return item;
}