本文整理汇总了C#中Dictionary.Reverse方法的典型用法代码示例。如果您正苦于以下问题:C# Dictionary.Reverse方法的具体用法?C# Dictionary.Reverse怎么用?C# Dictionary.Reverse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Dictionary
的用法示例。
在下文中一共展示了Dictionary.Reverse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ValidateUserNames
static void ValidateUserNames(string input)
{
string pattern = @"(?<=[\s\\\/]|^)([A-Za-z][A-Za-z0-9_]{3,25})";
Regex regex = new Regex(pattern);
MatchCollection matchCollection = regex.Matches(input);
Dictionary<int, string> sumOfUsernames = new Dictionary<int, string>();
for(int i = 0; i < matchCollection.Count - 1; i++)
{
string userNames = matchCollection[i].Value + " " + matchCollection[i + 1].Value;
int sumOfUsers = GetSumOfUserNames(userNames);
if(!sumOfUsernames.ContainsKey(sumOfUsers))
sumOfUsernames.Add(sumOfUsers, userNames);
}
SortedDictionary<int, string> sortedSum = new SortedDictionary<int, string>(sumOfUsernames);
foreach(KeyValuePair<int, string> key in sumOfUsernames.Reverse())
{
string[] userNames = key.Value.Split(' ').ToArray();
Console.WriteLine(userNames[0]);
Console.WriteLine(userNames[1]);
break;
}
}
示例2: CreateSearchNavigationNodes
internal static void CreateSearchNavigationNodes(ClientContext clientContext, Web web, Dictionary<string, string> searchNavigationNodes)
{
if (searchNavigationNodes == null || searchNavigationNodes.Count == 0) return;
var searchNavigation = web.Navigation.GetNodeById(1040);
NavigationNodeCollection nodeCollection = searchNavigation.Children;
clientContext.Load(searchNavigation);
clientContext.Load(nodeCollection);
clientContext.ExecuteQuery();
for (int i = nodeCollection.Count - 1; i >= 0; i--)
{
nodeCollection[i].DeleteObject();
}
foreach (KeyValuePair<string, string> newNode in searchNavigationNodes.Reverse<KeyValuePair<string, string>>())
{
nodeCollection.Add(new NavigationNodeCreationInformation
{
Title = newNode.Key,
Url = newNode.Value
});
}
clientContext.ExecuteQuery();
}
示例3: DataBind
public static void DataBind(this Motor engine, Route route)
{
var list = new Dictionary<string, object>();
var function = engine.RuntimeContext.Runnable.FunctionTable[route.Action];
var instructions = engine.RuntimeContext.Runnable.Instructions;
for (int i = function.EntryPoint; i < instructions.Length; i++)
{
var inst = instructions[i];
if (inst.OpCode == OpCode.DCL)
{
var value = route.Context.Request[inst.Operands[0].Value.ToString()] ?? string.Empty;
list.Add(inst.Operands[0].Value.ToString(), value);
}
if (inst.OpCode == OpCode.EMP) break;
}
foreach (var keypar in list.Reverse())
{
var op = new Operand(OperandType.Literal, keypar.Value);
engine.RuntimeContext.Runnable.ParamStack.Push(op);
}
}
示例4: MakeSchedule
static void MakeSchedule()
{
int currentDuration = 0;
trainScheduleForward = stationsInfo.ToDictionary(
kvp => stationsByName[kvp.Key],
kvp => currentDuration += kvp.Value
);
trainScheduleDuration = currentDuration;
trainScheduleBackwards = trainScheduleForward.Reverse().ToDictionary(
kvp => kvp.Key,
kvp => trainScheduleDuration - kvp.Value
);
#if DEBUG
Console.WriteLine("# Schedule");
Console.WriteLine(string.Join(Environment.NewLine, trainScheduleForward));
Console.WriteLine();
Console.WriteLine(string.Join(Environment.NewLine, trainScheduleBackwards));
Console.WriteLine();
#endif
}
示例5: UpdateParamsWithValues
public string UpdateParamsWithValues(string originalSql)
{
string[] parts = originalSql.Replace("N'", "'").Replace("''", "'").Split(';');
if (parts.Length <= 1)
return originalSql;
string sql = String.Join(";", parts.Take(parts.Length - 1).ToArray());
string paramList = parts.Last();
var parameters = new Dictionary<string, string>();
ITokenizer tokenizer = new SqlTokenizer(paramList);
tokenizer.ReadNextToken();
do
{
string parameter = tokenizer.Current.Value;
tokenizer.ReadNextToken();
tokenizer.ExpectToken(Constants.Assignment);
parameters.Add(parameter, ProcessParameter(tokenizer, parameter));
}
while (tokenizer.TokenEquals(Constants.Comma));
foreach (var item in parameters.Reverse())
sql = sql.Replace(item.Key, item.Value);
return sql;
}
示例6: MergeDictionaries
/// <summary>
/// Merge given dictionaries
/// </summary>
/// <param name="dictionaries">dictionaries to merge</param>
/// <param name="overrideDueplicateWithLatterDictionaryValue">
/// If true and duplicate key exists, then dupe key's values are overriden by latter dictionary values
/// </param>
public Dictionary<string, string> MergeDictionaries(
Dictionary<int, Dictionary<string, string>> dictionaries,
bool overrideDueplicateWithLatterDictionaryValue = true)
{
Dictionary<string, string> result = new Dictionary<string, string>(dictionaries.Count);
var query = overrideDueplicateWithLatterDictionaryValue ? dictionaries.Reverse() : dictionaries;
foreach (var index in query)
{
Dictionary<string, string> d2 = index.Value;
result = result.Concat(d2.Where(x => !result.Keys.Contains(x.Key))).ToDictionary(o => o.Key, o => o.Value);
}
return result;
}
示例7: ParseNodeInternal
private static void ParseNodeInternal(XElement element, DataSchemaKey key)
{
foreach (XElement el in element.Elements())
{
string name = el.Attribute("name").Value;
switch (el.Name.LocalName)
{
case "value" :
string mappedColumn = el.Value;
DataSchemaValue v = new DataSchemaValue(name, mappedColumn);
ParseNodeInternal(el, v);
key.AddChild(v);
break;
case "container" :
DataSchemaKey c = new DataSchemaKey(DataSchemaKeyType.Container, name);
ParseNodeInternal(el, c);
key.AddChild(c);
break;
case "iterator" :
int max = Int32.Parse(el.Attribute("maxItemCount").Value);
DataSchemaIterator i = new DataSchemaIterator(name, max);
ParseNodeInternal(el, i);
key.AddChild(i);
break;
case "iteratorValue" :
Dictionary<DataSchemaIterator,int> iterators = new Dictionary<DataSchemaIterator,int>();
FindIterators(key, iterators);
iterators.Reverse();
List<DataSchemaIteratorValueMappedColumn> columns = new List<DataSchemaIteratorValueMappedColumn>();
string tmpl = el.Value;
GenCoulumns(tmpl, iterators, columns, 0);
DataSchemaIteratorValue iv = new DataSchemaIteratorValue(name, columns);
ParseNodeInternal(el, iv);
key.AddChild(iv);
break;
}
}
}
示例8: TestDetermineHierarchyForContributingTemplates01
public void TestDetermineHierarchyForContributingTemplates01()
{
DetermineHierarchyTest test = new DetermineHierarchyTest();
// hierarchy mappings:
// A > B > C
// > D > E > F
// G >
// H > J
// I >
ContributingTemplateInSet templateA = test.CreateContributingTemplateInSet("A");
ContributingTemplateInSet templateB = test.CreateContributingTemplateInSet("B");
ContributingTemplateInSet templateC = test.CreateContributingTemplateInSet("C");
ContributingTemplateInSet templateD = test.CreateContributingTemplateInSet("D");
ContributingTemplateInSet templateE = test.CreateContributingTemplateInSet("E");
ContributingTemplateInSet templateF = test.CreateContributingTemplateInSet("F");
ContributingTemplateInSet templateG = test.CreateContributingTemplateInSet("G");
ContributingTemplateInSet templateH = test.CreateContributingTemplateInSet("H");
ContributingTemplateInSet templateI = test.CreateContributingTemplateInSet("I");
ContributingTemplateInSet templateJ = test.CreateContributingTemplateInSet("J");
Dictionary<TemplateInSetBase, IEnumerable<TemplateInSetBase>> mappings = new Dictionary<TemplateInSetBase, IEnumerable<TemplateInSetBase>>()
{
{templateA, null},
{templateB, new ContributingTemplateInSet[] { templateA }},
{templateC, new ContributingTemplateInSet[] { templateB }},
{templateD, new ContributingTemplateInSet[] { templateA }},
{templateE, new ContributingTemplateInSet[] { templateD }},
{templateF, new ContributingTemplateInSet[] { templateE }},
{templateG, null},
{templateH, new ContributingTemplateInSet[] { templateG, templateI }},
{templateI, null},
{templateJ, new ContributingTemplateInSet[] { templateH }}
};
mappings.Reverse();
test.Run(mappings);
Assert.IsNull(templateA.BaseContributingTemplatesInSet);
Assert.IsNull(templateG.BaseContributingTemplatesInSet);
Assert.IsNull(templateI.BaseContributingTemplatesInSet);
Assert.AreSame(templateA, templateB.BaseContributingTemplatesInSet.First());
Assert.AreSame(templateB, templateC.BaseContributingTemplatesInSet.First());
Assert.AreSame(templateA, templateD.BaseContributingTemplatesInSet.First());
Assert.AreSame(templateD, templateE.BaseContributingTemplatesInSet.First());
Assert.AreSame(templateE, templateF.BaseContributingTemplatesInSet.First());
Assert.AreSame(templateH, templateJ.BaseContributingTemplatesInSet.First());
Assert.IsTrue(templateH.BaseContributingTemplatesInSet.Contains(templateG));
Assert.IsTrue(templateH.BaseContributingTemplatesInSet.Contains(templateI));
Assert.IsFalse(templateC.BaseContributingTemplatesInSet.Contains(templateA));
Assert.IsFalse(templateF.BaseContributingTemplatesInSet.Contains(templateD));
Assert.IsFalse(templateF.BaseContributingTemplatesInSet.Contains(templateA));
Assert.IsFalse(templateE.BaseContributingTemplatesInSet.Contains(templateA));
Assert.IsFalse(templateJ.BaseContributingTemplatesInSet.Contains(templateG));
Assert.IsFalse(templateJ.BaseContributingTemplatesInSet.Contains(templateI));
}
示例9: TestDetermineHierarchy05
public void TestDetermineHierarchy05()
{
DetermineHierarchyTest test = new DetermineHierarchyTest();
// hierarchy mappings:
// A > B > C
// > D > E > F
// G > H
TemplateInSet templateA = test.CreateTemplateInSet("A");
TemplateInSet templateB = test.CreateTemplateInSet("B");
TemplateInSet templateC = test.CreateTemplateInSet("C");
TemplateInSet templateD = test.CreateTemplateInSet("D");
TemplateInSet templateE = test.CreateTemplateInSet("E");
TemplateInSet templateF = test.CreateTemplateInSet("F");
TemplateInSet templateG = test.CreateTemplateInSet("G");
TemplateInSet templateH = test.CreateTemplateInSet("H");
Dictionary<TemplateInSetBase, IEnumerable<TemplateInSetBase>> mappings = new Dictionary<TemplateInSetBase, IEnumerable<TemplateInSetBase>>()
{
{templateA, null},
{templateB, new TemplateInSet[] { templateA }},
{templateC, new TemplateInSet[] { templateB }},
{templateD, new TemplateInSet[] { templateA }},
{templateE, new TemplateInSet[] { templateD }},
{templateF, new TemplateInSet[] { templateE }},
{templateG, null},
{templateH, new TemplateInSet[] { templateG }}
};
mappings.Reverse();
test.Run(mappings);
Assert.IsNull(templateA.BaseTemplateInSet);
Assert.IsNull(templateG.BaseTemplateInSet);
Assert.AreSame(templateA, templateB.BaseTemplateInSet);
Assert.AreSame(templateB, templateC.BaseTemplateInSet);
Assert.AreSame(templateA, templateD.BaseTemplateInSet);
Assert.AreSame(templateD, templateE.BaseTemplateInSet);
Assert.AreSame(templateE, templateF.BaseTemplateInSet);
Assert.AreSame(templateG, templateH.BaseTemplateInSet);
}
示例10: MergeMatches
private static Dictionary<Game, int> MergeMatches(Dictionary<Game, int> matchList1, Dictionary<Game, int> matchList2)
{
var merged = new Dictionary<Game, int>();
int team1Index = 0;
foreach (var match in matchList1)
{
int team2Index = 0;
foreach (var otherMatch in matchList2.Reverse())
{
if(team2Index>team1Index)
{
break;
}
if(team1Index==team2Index)
{
merged.Add(new Game(match.Key.HomeTeam, otherMatch.Key.GuestTeam), match.Value);
}
team2Index++;
}
team1Index++;
}
return merged;
}
示例11: GetSubjectNameItemString
private static string GetSubjectNameItemString(Dictionary<string, string> dic)
{
var rev = dic.Reverse();
var sb = new StringBuilder();
foreach (var item in rev)
{
sb.Append(item.Key + "=" + item.Value + ",");
}
sb.Length--;
return sb.ToString();
}
开发者ID:compliashield,项目名称:compliashield-sdk-encryption,代码行数:12,代码来源:ProtectedX509Certificate2Generator.cs
示例12: GetPlaylists
public Playlist [] GetPlaylists (uint index, uint max_count, string order, bool reverse_order)
{
var playlist_sources = ServiceManager.SourceManager.FindSources<AbstractPlaylistSource> ();
switch (order) {
case "Alphabetical":
playlist_sources = playlist_sources.OrderBy (p => p.Name);
break;
case "UserDefined":
playlist_sources = playlist_sources.OrderBy (p => p.Order);
break;
}
if (reverse_order) {
playlist_sources = playlist_sources.Reverse ();
}
var playlists = new List<Playlist> ();
foreach (var pl in playlist_sources.Skip ((int)index).Take ((int)max_count)) {
playlists.Add (BuildPlaylistFromSource (pl));
}
return playlists.ToArray ();
}
示例13: CompareButton_OnClick
async private void CompareButton_OnClick(object sender, RoutedEventArgs e)
{
if (File.Exists(OldFilePathTextBox.Text) == false || File.Exists(NewFilePathTextBox.Text) == false) {
return;
}
OldFile = new FileInfo(OldFilePathTextBox.Text).FullName;
NewFile = new FileInfo(NewFilePathTextBox.Text).FullName;
CompareButton.Content = new Run("Comparing...");
Task<Dictionary<string, string>> fastDiffTask = Task.Run(() =>
{
Dictionary<string, string> diffTableDictionary = new Dictionary<string, string>();
//diffTableDictionary.Add("-----", string.Empty);
using (SQLiteConnection connection = new SQLiteConnection(DAL.ConnectionString)) {
connection.Open();
//连接两个库
string attachSql = "ATTACH '" + OldFile + "' AS old;ATTACH '" + NewFile + "' AS new;";
SQLiteCommand attachCommand = new SQLiteCommand(attachSql, connection);
attachCommand.ExecuteNonQuery();
//循环每个表
foreach (MASTERDB type in Enum.GetValues(typeof(MASTERDB))) {
if (type == MASTERDB.LEVEL_DATA_MASTER) {
//地图表没啥比对价值
continue;
}
//检查表存在性
SQLiteCommand existCommand = new SQLiteCommand(string.Format(ExistSql, type.ToString()), connection);
int existCount = Convert.ToInt32(existCommand.ExecuteScalar());
if (existCount == 1) {
//只有一边存在
diffTableDictionary.Add("[New]" + type.ToString(), type.ToString());
}
else if (existCount == 2) {
//检查数据是否存在差异
int oldHasNew = 0, newHasNew = 0;
string hasDiffMark = string.Empty;
try {
existCommand.CommandText = string.Format(ExistInNewSql, type.ToString());
if (existCommand.ExecuteScalar() != null) {
newHasNew = 1;
}
existCommand.CommandText = string.Format(ExistInOldSql, type.ToString());
if (existCommand.ExecuteScalar() != null) {
oldHasNew = 1;
}
switch ((oldHasNew << 1) | newHasNew) {
case 3: { hasDiffMark = "←→"; break; }
case 2: { hasDiffMark = "← "; break; }
case 1: { hasDiffMark = " →"; break; }
default: break;
}
}
catch (Exception) {
//表结构发生变化
//todo 不出异常的解决方案
hasDiffMark = "Cng";
}
if (string.IsNullOrEmpty(hasDiffMark) == false) {
diffTableDictionary.Add("[" + hasDiffMark + "]" + type.ToString(), type.ToString());
}
}
}
}
//trick to add to dict first
var reverseDict = diffTableDictionary.Reverse().ToDictionary(pair => pair.Key, pair => pair.Value);
reverseDict.Add("Results:" + diffTableDictionary.Count, "");
return reverseDict.Reverse().ToDictionary(pair => pair.Key, pair => pair.Value);
});
TableSelectComboBox.ItemsSource = await fastDiffTask;
TableSelectComboBox.SelectedIndex = 0;
CompareButton.Content = new Run("Compare");
}
示例14: BenjaminiHochberg
private Dictionary<string, double> BenjaminiHochberg(Dictionary<string, double> pvalueDict)
{
Dictionary<string, double> tempretDict = new Dictionary<string, double>();
Dictionary<string, double> retDict = new Dictionary<string, double>();
Dictionary<string, double> sortedDict = pvalueDict.OrderBy(x => x.Value).ToDictionary(x => x.Key, x => x.Value);
int count = 1;
foreach (KeyValuePair<string, double> kvp in sortedDict)
{
double qValue = kvp.Value * sortedDict.Values.Count / (count);
tempretDict.Add(kvp.Key, qValue);
count++;
}
Dictionary<string, double> reverseSortedDict = tempretDict.Reverse().ToDictionary(x => x.Key, x => x.Value);
int i = 0;
foreach (KeyValuePair<string, double> kvp in reverseSortedDict)
{
if (i != 0)
{
if (retDict.ElementAt(i - 1).Value < kvp.Value)
{
retDict.Add(kvp.Key, retDict.ElementAt(i - 1).Value);
}
else
{
retDict.Add(kvp.Key, kvp.Value);
}
}
else
{
retDict.Add(kvp.Key, kvp.Value);
}
i++;
}
return retDict;
}
示例15: Build
private static void Build(string file)
{
var jumpTable = new Dictionary<string, ushort>();
string directory = Path.GetDirectoryName(Path.GetFullPath(file));
string[] lines = File.ReadAllLines(file);
bool waitEndIf = false;
foreach (var _line in lines)
{
string line = _line.Trim();
if (line.StartsWith("#") || string.IsNullOrEmpty(line))
continue;
if (waitEndIf)
{
if (line == "endif")
waitEndIf = false;
else
continue;
}
if (line.StartsWith("asm "))
{
string[] parts = line.Split(' ');
if (verbose)
Console.WriteLine("Assemling " + parts[1]);
Spasm(Path.Combine(directory, parts[1]), Path.Combine(directory, parts[2]), null, configuration);
}
else if (line.StartsWith("if "))
waitEndIf = configuration != line.Substring(3);
else if (line.StartsWith("link "))
{
string[] parts = line.Split(' ');
byte[] data = new byte[int.Parse(parts[3], NumberStyles.HexNumber)];
for (int i = 0; i < data.Length; i++)
data[i] = 0xFF;
using (Stream stream = File.Open(Path.Combine(directory, parts[1]), FileMode.Open))
stream.Read(data, 0, (int)stream.Length);
output.Seek(int.Parse(parts[2], NumberStyles.HexNumber), SeekOrigin.Begin);
output.Write(data, 0, data.Length);
output.Flush();
}
else if (line.StartsWith("echo "))
Console.WriteLine(line.Substring(5));
else if (line.StartsWith("load "))
LoadLabels(Path.Combine(directory, line.Substring(5)));
else if (line.StartsWith("jump finish "))
{
// C3 34 12
string[] parts = line.Split(' ');
int tableAddress = int.Parse(parts[2], NumberStyles.HexNumber);
output.Seek(tableAddress - (jumpTable.Count * 3), SeekOrigin.Begin);
string include = "";
foreach (var jumpValue in jumpTable.Reverse())
{
byte[] value = BitConverter.GetBytes(jumpValue.Value);
include = jumpValue.Key + " .equ $" + ((ushort)output.Position).ToString("X4") + Environment.NewLine + include;
output.Write(new byte[]
{
0xC3, // jp
value[0],
value[1]
}, 0, 3);
}
include = ";This file was generated by a tool" + Environment.NewLine + include;
File.WriteAllText(Path.Combine(directory, parts[3]), include);
}
else if (line.StartsWith("jump include "))
jumpTable.Add(line.Substring(13), (ushort)labels[line.Substring(13).ToLower()]);
else if (line.StartsWith("rm "))
{
string[] parts = line.Substring(3).Split(' ');
foreach (var part in parts)
{
if (File.Exists(Path.Combine(directory, part)))
File.Delete(Path.Combine(directory, part));
if (Directory.Exists(Path.Combine(directory, part)))
Directory.Delete(Path.Combine(directory, part), true);
}
}
else if (line.StartsWith("cp"))
{
string[] parts = line.Substring(3).Split(' ');
File.Copy(Path.Combine(directory, parts[0]), Path.Combine(directory, parts[1]));
}
else if (line.StartsWith("mkdir "))
Directory.CreateDirectory(Path.Combine(directory, line.Substring(6)));
else if (line.StartsWith("fscreate "))
CreateFilesystem(Path.Combine(directory, line.Substring(9)));
else if (line.StartsWith("pages "))
{
var parts = line.Substring(6).Split(' ');
foreach (var part in parts)
AddPage(byte.Parse(part, NumberStyles.HexNumber));
}
else if (line == "endif") { }
else
{
Console.WriteLine("Unknown build directive: " + line);
throw new InvalidOperationException("Unknown build directive");
}
}
}