本文整理汇总了C#中System.Collections.Dictionary.Where方法的典型用法代码示例。如果您正苦于以下问题:C# Dictionary.Where方法的具体用法?C# Dictionary.Where怎么用?C# Dictionary.Where使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Dictionary
的用法示例。
在下文中一共展示了Dictionary.Where方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetSelectedFirewallGroups
public static List<FirewallGroup> GetSelectedFirewallGroups(Dictionary<String, List<String>> FirewallGroups, IList SelectedFirewallGroups)
{
List<FirewallGroup> fwgrps = null;
if (FirewallGroups != null)
{
fwgrps = new List<FirewallGroup>();
FirewallGroup fwgrp = null;
foreach (string grp in SelectedFirewallGroups)
{
fwgrp = new FirewallGroup();
fwgrp.GroupName = grp.ToString();
fwgrp.URLs = new List<string>();
var selectedgroups = FirewallGroups.Where(selectedgrp => selectedgrp.Key == grp);
if (selectedgroups != null)
{
foreach (var selectedgroup in selectedgroups)
{
fwgrp.URLs.AddRange(selectedgroup.Value);
fwgrps.Add(fwgrp);
}
}
}
}
return fwgrps;
}
示例2: ReadSubFingerprintDataByHashBucketsWithThreshold
public IEnumerable<SubFingerprintData> ReadSubFingerprintDataByHashBucketsWithThreshold(
long[] hashBins, int thresholdVotes)
{
int table = 0;
var hashTables = storage.HashTables;
var subFingeprintCount = new Dictionary<IModelReference, int>();
foreach (var hashBin in hashBins)
{
if (hashTables[table].ContainsKey(hashBin))
{
foreach (var subFingerprintId in hashTables[table][hashBin])
{
if (!subFingeprintCount.ContainsKey(subFingerprintId))
{
subFingeprintCount[subFingerprintId] = 0;
}
subFingeprintCount[subFingerprintId]++;
}
}
table++;
}
return subFingeprintCount.Where(pair => pair.Value >= thresholdVotes)
.Select(pair => storage.SubFingerprints[pair.Key]);
}
示例3: CanPermutePalindrome
private bool CanPermutePalindrome(string s)
{
if (string.IsNullOrEmpty(s)) return true;
int length = s.Length;
var dic = new Dictionary<char, int>();
for (int index = 0; index < length; index++)
if (dic.ContainsKey(s[index]))
dic[s[index]]++;
else
dic.Add(s[index],1);
return dic.Where(p => p.Value % 2 == 1).Count()<=1;
}
示例4: cleanCoordinates
private static string cleanCoordinates(string poly)
{
Dictionary<int, string> scondSplit = new Dictionary<int, string>();
//CLEANING STRING FROM NON-COORDINATES CHARACTERS
int pos = poly.LastIndexOf('(') + 1;
string firstHalf = poly.Substring(0, pos);
string secondHalf = poly.Substring(pos);
try
{
//ADD UNIQUE ITEMS TO THE DICTIONARY
int j = 0;
int i, dPos;
string coordinates;
for (i = 0; i < secondHalf.Length; i++)
{
coordinates = "";
dPos = secondHalf.IndexOf(", ", i);
if (dPos > -1)
{
coordinates = secondHalf.Substring(i, dPos - i);
i = dPos + 1;
if (scondSplit.Where(x => x.Value == coordinates).Count() == 0)
scondSplit.Add(j++, coordinates);
}
else
{
scondSplit.Add(j, secondHalf.Substring(i));
break;
}
}
}
finally
{
if (scondSplit.Count > 0)
{ //CONCATENATION OF POLY
poly = firstHalf;
foreach (var pair in scondSplit)
{
poly += pair.Value + ", ";
}
poly = poly.Substring(0, poly.Length - 2);
}
}
return poly;
}
示例5: InferCellTypeForColumn
/// <summary>
/// Attempts to infer the type of cells present by obtaining
/// the first 30 cells and counting the possible types.
/// </summary>
/// <returns>The cell type for column.</returns>
/// <param name="column">The column to use.</param>
public Type InferCellTypeForColumn(string column)
{
string startRow = "1";
string endRow = "30";
ICollection<ICell> cells = _dataSource.GetCells (column, startRow, endRow);
IDictionary<Type, int> typeCounts = new Dictionary<Type, int>();
foreach (ICell cell in cells) {
int oldValue = 0;
if (typeCounts.TryGetValue(cell.GetType(), out oldValue)) {
typeCounts.Add(cell.GetType(), oldValue + 1);
} else {
typeCounts.Add (cell.GetType(), 0);
}
}
int max = typeCounts.Max (k => k.Value);
return typeCounts.Where(k => k.Value.Equals(max)).FirstOrDefault().Key;
}
示例6: Logit_Reg_Check
public bool Logit_Reg_Check()
{
Dictionary<string, string> depDic = new Dictionary<string, string>();
if (ViewState["dict"] != null)
{ depDic = (Dictionary<string, string>)ViewState["dict"]; }
if (depDic.Count > 0 && depDic.Values.Contains("i") && depDic.Values.Contains("d"))
{
foreach (KeyValuePair<string, string> kp in depDic.Where(D => D.Value.Contains("d")))
{
List<string> logits = (List<string>) ViewState["logits"];
if (logits != null && logits.Count > 0 && logits.Contains(kp.Key))
{
return true;
}
}
}
return false;
}
示例7: EncodeUsing
public static string EncodeUsing(this string inputString, Dictionary<string, string> huffmanCodesToSymbols)
{
var encodedMessage = new StringBuilder();
foreach (char c in inputString)
{
var correspondingHuffmanCodes = huffmanCodesToSymbols.Where(kvp => kvp.Value == c.ToString());
if (correspondingHuffmanCodes.Count() > 1)
{
throw new ArgumentException(String.Format("The character '{0}' has more than one corresponding Huffman code.", c));
}
encodedMessage.Append(correspondingHuffmanCodes.First().Key);
}
return encodedMessage.ToString();
}
示例8: InstanceContext
public InstanceContext(Dictionary<Type, SitecoreClassConfig> classes, IEnumerable<AbstractSitecoreDataHandler> datas)
{
//This needs reworking
//this will be simplified to remove the need for three sets of data
Classes = classes;
ClassesById = new Dictionary<Guid, IList<SitecoreClassConfig>>();
foreach (var record in classes.Where(x => x.Value.TemplateId != Guid.Empty))
{
if (!ClassesById.ContainsKey(record.Value.TemplateId))
{
ClassesById.Add(record.Value.TemplateId, new List<SitecoreClassConfig>());
}
ClassesById[record.Value.TemplateId].Add(record.Value);
}
Datas = datas;
}
示例9: GetTeams
public static Dictionary<int, string> GetTeams(FederationsEnum federationUrl)
{
bool isFemale = federationUrl == FederationsEnum.WFTDA;
var db = new ManagementContext();
// Display all Teams from the database
var getTeamsByFederation = from b in db.RTeams
where b.IsFemale == isFemale && b.IsDeleted == false
orderby b.Name
select b;
Dictionary<int, string> dicSessions = new Dictionary<int, string>();
foreach (var item in getTeamsByFederation)
{
if (dicSessions.Where(x => x.Key == item.ID).FirstOrDefault().Key != item.ID)
dicSessions.Add(item.ID, item.Name);
}
return dicSessions;
}
示例10: SerializeAttributes
private void SerializeAttributes(Dictionary<string, CfgMetadata> meta, object obj, StringBuilder sb) {
if (meta.Count > 0) {
var pairs = meta.Where(kv => kv.Value.ListType == null).ToArray();
for (var i = 0; i < pairs.Length; i++) {
var pair = pairs[i];
if (!pair.Value.Attribute.serialize) {
continue;
}
var value = pair.Value.Getter(obj);
if (value == null || value.Equals(pair.Value.Attribute.value) || (!pair.Value.Attribute.ValueIsSet && pair.Value.Default != null && pair.Value.Default.Equals(value))) {
continue;
}
var type = pair.Value.PropertyInfo.PropertyType;
var stringValue = ValueToString(type, value);
sb.Append(" \"");
sb.Append(pair.Key);
sb.Append("\":");
sb.Append(stringValue);
sb.Append(",");
}
} else if (obj is Dictionary<string, string>) {
var dict = (Dictionary<string, string>)obj;
foreach (var pair in dict) {
sb.Append(" \"");
sb.Append(pair.Key);
sb.Append("\":\"");
sb.Append(Encode(pair.Value));
sb.Append("\"");
sb.Append(",");
}
}
}
示例11: TypeForCategoryJsonArray
private ArrayList TypeForCategoryJsonArray(string Category)
{
ArrayList typeList = new ArrayList();
dictionaryItem = TestTypes.TypeWithSecureFlag(Category);
isSecuredFlag = dictionaryItem != null && dictionaryItem.Where(x => Boolean.Parse(x.Value.ToString())).Select(y => y.Key).ToList().Distinct().Any();
if (dictionaryItem != null && dictionaryItem.Select(c => c.Key).Any())
{
if (isSecuredFlag && UserHasPermission(Permission.Access_SecureTesting))
{
typeList.Add(new object[] { dictionaryItem.Select(c => c.Key).ToArray() });
}
else
{
typeList.Add(new object[] { dictionaryItem.Where(c => !c.Value).Select(c => c.Key).ToArray() });
}
}
return typeList;
}
示例12: RematerilizeExtrenalNodeTableReference
/// <summary>
/// If a table alias in the MATCH clause is defined in an upper-level context,
/// to be able to translate this MATCH clause, this table alias must be re-materialized
/// in the FROM clause of the current context and joined with the corresponding table
/// in the upper-level context.
/// </summary>
/// <param name="query">Select query</param>
/// <param name="nodes">A collection of node alias and match node instance</param>
private void RematerilizeExtrenalNodeTableReference(WSelectQueryBlock query, Dictionary<string, MatchNode> nodes)
{
var tableRefs = query.FromClause.TableReferences;
var tableSet = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
var newTableRefs = new List<WTableReference>();
for (int index = 0; index < tableRefs.Count; ++index)
{
var table = tableRefs[index] as WNamedTableReference;
if (table == null)
{
newTableRefs.Add(tableRefs[index]);
continue;
}
if (!nodes.ContainsKey(table.ExposedName.Value))
{
newTableRefs.Add(table);
}
else
{
tableSet.Add(table.ExposedName.Value);
}
}
query.FromClause = new WFromClause
{
TableReferences = newTableRefs,
};
WBooleanExpression whereCondiction = null;
foreach (var node in nodes.Where(node => !tableSet.Contains(node.Key)))
{
node.Value.External = true;
var newWhereCondition = new WBooleanComparisonExpression
{
ComparisonType = BooleanComparisonType.Equals,
FirstExpr = new WColumnReferenceExpression
{
MultiPartIdentifier = new WMultiPartIdentifier(
new Identifier { Value = node.Key },
new Identifier { Value = "GlobalNodeId" })
},
SecondExpr = new WColumnReferenceExpression
{
MultiPartIdentifier = new WMultiPartIdentifier(
new Identifier { Value = node.Value.RefAlias },
new Identifier { Value = "GlobalNodeId" })
},
};
whereCondiction = WBooleanBinaryExpression.Conjunction(whereCondiction, newWhereCondition);
}
if (whereCondiction != null)
{
if (query.WhereClause == null)
{
query.WhereClause = new WWhereClause { SearchCondition = whereCondiction };
}
else
{
if (query.WhereClause.SearchCondition == null)
{
query.WhereClause.SearchCondition = whereCondiction;
}
else
{
query.WhereClause.SearchCondition = new WBooleanBinaryExpression
{
BooleanExpressionType = BooleanBinaryExpressionType.And,
FirstExpr = new WBooleanParenthesisExpression
{
Expression = query.WhereClause.SearchCondition
},
SecondExpr = new WBooleanParenthesisExpression
{
Expression = whereCondiction
}
};
}
}
}
}
示例13: GetProperties
static Dictionary<string, string> GetProperties(Dictionary<string, object> input)
{
string[] ignoreKeys = new []{ "targets", "actions", "thresholds" };
return input.Where(item => !ignoreKeys.Contains(item.Key))
.ToDictionary(item => item.Key, item => item.Value as string);
}
示例14: GetMostCommonGotos
private static short[] GetMostCommonGotos(IEnumerable<GotoTableValue> gotos, int maxToken)
{
var defaultGotos = new short[maxToken];
var gotoCounts = new Dictionary<Tuple<int, int>, int>();
foreach (var g in gotos)
{
var t = new Tuple<int, int>(g.Token, g.NewState);
if (!gotoCounts.ContainsKey(t))
gotoCounts.Add(t, 0);
gotoCounts[t] = gotoCounts[t] + 1;
}
// For every token in the grammar, store the most stored count as the default goto
for (int t = 0; t < maxToken; ++t)
{
var mostCommonNewState = gotoCounts.Where(f => f.Key.Item1 == t).OrderBy(f => -f.Value).Select(f => f.Key.Item2);
defaultGotos[t] = (short) mostCommonNewState.First();
}
return defaultGotos;
}
示例15: DecodeDateSearch
/// <summary>
/// This will find the string name of the date facet based off the JSON parse query from the handler
/// </summary>
/// <returns>The name of the facet</returns>
/// <value>Within a Year</value>
/// <param name="dateTime">The JSON date</param>
/// <param name="listOfDates">The available facets</param>
private static string DecodeDateSearch(DateTime dateTime, Dictionary<DateTime, string> listOfDates)
{
return listOfDates.Where(date => date.Key.ToString() == dateTime.ToString()).First().Value;
}