本文整理汇总了C#中SortedDictionary.OrderByDescending方法的典型用法代码示例。如果您正苦于以下问题:C# SortedDictionary.OrderByDescending方法的具体用法?C# SortedDictionary.OrderByDescending怎么用?C# SortedDictionary.OrderByDescending使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SortedDictionary
的用法示例。
在下文中一共展示了SortedDictionary.OrderByDescending方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
string[] filenames = Directory.GetFiles("../../", ".", SearchOption.AllDirectories).ToArray();
var dbDictionary = new SortedDictionary<string, List<string>>();
foreach (var filename in filenames)
{
FileInfo name = new FileInfo(filename);
if (dbDictionary.ContainsKey(name.Extension))
{
dbDictionary[name.Extension].Add(string.Format("{0}.{1} - {2}kb", name.Name, name.Extension,
name.Length));
}
else
{
dbDictionary.Add(name.Extension,
new List<string> { string.Format("{0}.{1} - {2}kb", name.Name, name.Extension, name.Length) });
}
}
string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
using (StreamWriter writer = new StreamWriter(path + "/results.txt"))
{
foreach (var list in dbDictionary.OrderByDescending(s => s.Value.Count))
{
writer.WriteLine(list.Key);
foreach (var str in list.Value)
{
writer.WriteLine("--" + str);
}
}
}
}
示例2: DirectoryReport
static void DirectoryReport(string dir)
{
string[] files = Directory.GetFiles(dir);
SortedDictionary<string, int> filesExtensions = new SortedDictionary<string, int>();
for (int i = 0; i < files.Length; i++)
{
string fileExt = CutExtension(files[i]);
if (!filesExtensions.ContainsKey(fileExt))
{
filesExtensions.Add(fileExt,GetExtensionRepetitions(files,fileExt));
}
}
using (StreamWriter writer = new StreamWriter(Environment.GetFolderPath(Environment.SpecialFolder.Desktop)+"\\report.txt"))
{
writer.WriteLine("Report for the directory \"{0}\"",new DirectoryInfo(dir).FullName);
writer.WriteLine("----------------------------\r\n");
foreach (var item in filesExtensions.OrderByDescending(a => a.Value))
{
writer.WriteLine(item.Key);
string[] currentExtensionFiles = files.Select(a => a).Where(a => CutExtension(a).Equals(item.Key)).ToArray();
long fileSize = 0;
foreach (string f in currentExtensionFiles.OrderBy(a => new FileInfo(a).Length))
{
fileSize = new FileInfo(f).Length;
writer.WriteLine("--{0} - {1:F2}kb", f.Substring(f.LastIndexOf('\\') + 1), fileSize / 1024d);
}
}
}
Console.WriteLine("The report was generated successfully. You can find it in your Desktop folder.");
}
示例3: Main
static void Main()
{
string path = Console.ReadLine();
var extentions = new SortedDictionary<string, Dictionary<string, double>>();
DirectoryInfo directory = new DirectoryInfo(path);
foreach (var file in directory.GetFiles())
{
if (extentions.ContainsKey(file.Extension))
{
extentions[file.Extension].Add("--" + file.Name + " - ", file.Length);
}
else
{
extentions.Add(file.Extension, new Dictionary<string, double> { { file.Name, file.Length } });
}
}
var result = extentions.OrderByDescending(p => p.Value.Count).ThenBy(p => p.Key);
using (var writer = new StreamWriter(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "/report.txt"))
{
foreach (var extention in result)
{
writer.WriteLine(extention.Key);
var sortedSubDict = extention.Value.OrderBy(p => p.Value);
foreach (var pair in sortedSubDict)
{
writer.WriteLine("--{0} - {1:F3}kb", pair.Key, pair.Value / 1024);
}
}
}
}
示例4: Main
private static void Main(string[] args)
{
StreamReader reader = new StreamReader("../../wordFile.txt");
StreamReader readerSearchFile = new StreamReader("../../textFile.txt");
StreamWriter writer = new StreamWriter("../../resultFile.txt");
try
{
SortedDictionary<String, int> words = new SortedDictionary<string, int>();
string word = reader.ReadLine();
string textFile = readerSearchFile.ReadToEnd().ToLower();
while (word != null)
{
word = word.ToLower();
string pattern = @"\b" + word + @"\b";
MatchCollection matches = Regex.Matches(textFile, pattern);
words.Add(word, matches.Count);
word = reader.ReadLine();
}
var ordered = words.OrderByDescending(pair => pair.Value);
foreach (KeyValuePair<string, int> pair in ordered)
{
writer.WriteLine("{0} - {1}", pair.Key, pair.Value);
}
}
finally
{
writer.Flush();
reader.Dispose();
readerSearchFile.Dispose();
writer.Dispose();
}
}
示例5: Main
static void Main(string[] args)
{
using (StreamReader reader1 = new StreamReader("..\\..\\words.txt"),
reader2 = new StreamReader("..\\..\\text.txt"))
{
using(StreamWriter writer = new StreamWriter("..\\..\\result.txt"))
{
StringBuilder text = new StringBuilder();
while (!reader2.EndOfStream)
{
text.Append(reader2.ReadLine());
}
string word = reader1.ReadLine();
uint repetitions = 0;
SortedDictionary<string, uint> words = new SortedDictionary<string, uint>();
while (word!=null)
{
repetitions = GetRepetitions(word,text.ToString());
words.Add(word,repetitions);
word = reader1.ReadLine();
}
foreach (var item in words.OrderByDescending(item => item.Value))
{
writer.WriteLine("{0} - {1}",item.Key,item.Value);
}
}
}
}
示例6: GetRelatedPosts
/// <summary>
/// Returns related by tag nodes.
/// Sorted by score: more tags in common - bigger score. Same score item order is randomized.
/// </summary>
/// <param name="node"></param>
/// <param name="limit"></param>
/// <param name="doctypeAlias">filter by document type</param>
/// <param name="fieldAlias"></param>
/// <returns></returns>
public static IEnumerable<IPublishedContent> GetRelatedPosts(this IPublishedContent node, int limit = 10, string doctypeAlias = "", string fieldAlias = "tags")
{
var result = new List<IPublishedContent>();
if (node.HasValue(fieldAlias))
{
var scoredList = new SortedDictionary<int, List<IPublishedContent>>();
var tagsValue = node.GetPropertyValue<string>(fieldAlias);
var tags = tagsValue.Split(new string[] {","}, StringSplitOptions.RemoveEmptyEntries);
var relatedPosts = Tag.GetDocumentsWithTags(tagsValue).Where(x => x.Id != node.Id);
//fill scoredList
foreach (var post in relatedPosts)
{
if ((!String.IsNullOrEmpty(doctypeAlias) && post.ContentType.Alias == doctypeAlias) || String.IsNullOrEmpty(doctypeAlias))
{
var relatedNode = UmbracoContext.Current.ContentCache.GetById(post.Id);
//calculate score
var postTags = Tag.GetTags(relatedNode.Id);
var commonTagCount = 0;
foreach (var tag in tags)
{
if (postTags.FirstOrDefault(x => x.TagCaption == tag) != null)
{
commonTagCount++;
}
}
var list = scoredList.ContainsKey(commonTagCount)
? scoredList[commonTagCount]
: new List<IPublishedContent>();
list.Add(relatedNode);
scoredList[commonTagCount] = list;
}
}
//fill results
foreach (var item in scoredList.OrderByDescending(x => x.Key))
{
var items = item.Value.Count() > 1
? item.Value.RandomOrder() //can be replaced with other solution (based on view count, etc.)
: item.Value;
result.AddRange(items);
if (result.Count() >= limit)
{
break;
}
}
}
return result.Take(limit);
}
示例7: PrintLeftovers
private static void PrintLeftovers(SortedDictionary<string, int> items, SortedDictionary<string, int> junk)
{
foreach (var item in items.OrderByDescending(i => i.Value))
{
Console.WriteLine($"{item.Key}: {item.Value}");
}
foreach (var pieceOfJunk in junk)
{
Console.WriteLine($"{ pieceOfJunk.Key}: { pieceOfJunk.Value}");
}
}
示例8: DirectoryReport
static void DirectoryReport(string dir)
{
string[] files = Directory.GetFiles(dir);
SortedDictionary<string, int> filesExtensions = new SortedDictionary<string, int>();
for (int i = 0; i < files.Length; i++)
{
string fileExt = CutExtension(files[i]);
if (!filesExtensions.ContainsKey(fileExt))
{
filesExtensions.Add(fileExt, GetExtensionRepetitions(files, fileExt));
}
}
report.Append(String.Format("\r\nReport for the directory \"{0}\"", new DirectoryInfo(dir).FullName));
report.Append("\r\n----------------------------");
foreach (var item in filesExtensions.OrderByDescending(a => a.Value))
{
report.Append("\r\n"+item.Key);
string[] currentExtensionFiles = files.Select(a => a).Where(a => CutExtension(a).Equals(item.Key)).ToArray();
long fileSize = 0;
foreach (string f in currentExtensionFiles.OrderBy(a => new FileInfo(a).Length))
{
fileSize = new FileInfo(f).Length;
report.Append(String.Format("\r\n--{0} - {1:F2}kb", f.Substring(f.LastIndexOf('\\') + 1), fileSize / 1024d));
}
report.Append("\r\n");
}
if (dirCounter==0)
{
subDirs = Directory.GetDirectories(dir);
}
if(dirCounter == subDirs.Length)
{
using (StreamWriter writer = new StreamWriter(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\report.txt"))
{
writer.WriteLine(report.ToString());
}
return;
}
if(dirCounter<subDirs.Length)
{
DirectoryReport(subDirs[dirCounter]);
dirCounter++;
}
}
示例9: Main
static void Main(string[] args)
{
StreamReader readerText = new StreamReader("../../Text.txt");
StreamReader readerWords = new StreamReader("../../words.txt");
StreamWriter writer = new StreamWriter("../../result.txt");
List<string> words = new List<string>();
SortedDictionary<string, int> result = new SortedDictionary<string, int>();
//First Part.Reading the files
using (readerText)
{
using(readerWords)
{
words = WordsToMatch(readerWords);
string line = readerText.ReadToEnd();
for (int i = 0; i < words.Count; i++)
{
string pattern = String.Format(@"\b{0}\b", words[i]);
Regex regex = new Regex(pattern,RegexOptions.IgnoreCase);
int numberOfTimes = 0; // the word is matched.
MatchCollection matches = regex.Matches(line);
foreach (var match in matches)
{
numberOfTimes++;
}
result.Add(words[i],numberOfTimes);
}
}
}
// Second Part writing in the text file the result.
using (writer)
{
foreach (var item in result.OrderByDescending(key => key.Value))
{
writer.WriteLine("{0} - {1}",item.Key,item.Value);
}
}
}
示例10: WritungOnFile
private static void WritungOnFile(StreamWriter writer, SortedDictionary<string, Dictionary<string, double>> extension)
{
var orderedExtensions = extension // ordering the main dictionarie by the count inner dictionaries.
.OrderByDescending(extension => extension.Value.Count)
.ThenBy(extension => extension.Key);
foreach (var extension in orderedExtensions)
{
writer.WriteLine(extension.Key); // writing the type of extension.
var orderedDic = extension.Value.OrderBy(dic => dic.Value); // ordering the innerDictionaries by their value
foreach (var dic in orderedDic)
{
writer.WriteLine("{0}{1:F2}kb", dic.Key, dic.Value / 1024); // writing the files name with the kilobytes.
}
}
}
示例11: Main
static void Main(string[] args)
{
SortedDictionary<string, int> dictionary = new SortedDictionary<string, int>();
string inputWords = File.ReadAllText("../../words.txt");
string[] words = inputWords.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
String pattern = @"[a-zA-Z']+";
Regex regex = new Regex(pattern);
using (var reader = new StreamReader("../../text.txt"))
{
string currentSentcence = reader.ReadLine();
while (currentSentcence != null)
{
foreach (Match match in regex.Matches(currentSentcence))
{
for (int i = 0; i < words.Length; i++)
{
if (match.Value.ToLower() == words[i] && !(dictionary.ContainsKey(words[i])))
{
dictionary.Add(words[i], 1);
}
else if (match.Value.ToLower() == words[i])
{
dictionary[words[i]]++;
}
}
}
currentSentcence = reader.ReadLine();
}
foreach (var item in dictionary.OrderByDescending(key => key.Value))
{
Console.WriteLine("{0} - {1}", item.Key, item.Value);
}
}
}
示例12: GetCount
public FreqResult GetCount(IEnumerable<string> words)
{
var uniqueWords = new SortedDictionary<string, int>();
foreach (var word in words)
{
if (uniqueWords.ContainsKey(word))
{
uniqueWords[word]++;
}
else
{
uniqueWords.Add(word, 1);
}
}
var result = uniqueWords.OrderByDescending(pair => pair.Value);
return new FreqResult(uniqueWords.Count, result.Take(10));
}
示例13: SortAndWrite
private static void SortAndWrite(SortedDictionary<string, Dictionary<string, double>> extensions)
{
var sortedExtensions = extensions.OrderByDescending(p => p.Value.Count).ThenBy(ext => ext.Key);
string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\result.txt";
using (StreamWriter destination = new StreamWriter(desktopPath, true))
{
foreach (var file in sortedExtensions)
{
destination.WriteLine(file.Key);
var orderedDic = file.Value.OrderBy(p => p.Value);
foreach (var fileInformation in orderedDic)
{
destination.WriteLine(string.Format("{0}{1:F}kb", fileInformation.Key, fileInformation.Value / 1024));
}
}
}
}
示例14: Main
static void Main(string[] args)
{
string line;
SortedDictionary<string, int> wordIt = new SortedDictionary<string, int>();
using (StreamReader words = new StreamReader(@"..\..\words.txt"))
{
using (StreamReader text = new StreamReader(@"..\..\text.txt"))
{
while ((line = words.ReadLine()) != null)
{
wordIt.Add(line, 0);
}
while ((line = text.ReadLine()) != null)
{
string pattern = @"[^\w+]";
string[] substrings = Regex.Split(line, pattern).Where(n => !string.IsNullOrEmpty(n)).ToArray();
foreach (string match in substrings)
{
if (wordIt.ContainsKey(match.ToLower()))
{
int counter = wordIt[match.ToLower()];
wordIt[match.ToLower()] = counter + 1;
}
}
}
}
}
foreach (KeyValuePair<string, int> item in wordIt.OrderByDescending(key => key.Value))
{
Console.WriteLine("{0} - {1}", item.Key, item.Value);
}
}
示例15: Initialize
public void Initialize(ISimulationBase openSim)
{
try
{
//Check whether this is enabled
IConfig updateConfig = openSim.ConfigSource.Configs["Update"];
if (updateConfig == null || updateConfig.GetString("Module", string.Empty) != Name || !updateConfig.GetBoolean("Enabled", false))
{
return;
}
InfoMsg("Checking for updates...");
string WebSite = m_urlToCheckForUpdates;
// Call the github API
OSD data = OSDParser.DeserializeJson(Utilities.ReadExternalWebsite(WebSite));
if (data.Type != OSDType.Array)
{
ErrorMsg("Failed to get downloads from github API.");
return;
}
OSDArray JsonData = (OSDArray)data;
if (JsonData.Count == 0)
{
ErrorMsg("No downloads found.");
return;
}
else
{
TraceMsg(JsonData.Count + " downloads found, parsing.");
}
SortedDictionary<Version, OSDMap> releases = new SortedDictionary<Version, OSDMap>();
foreach (OSD map in JsonData)
{
if (map.Type == OSDType.Map)
{
OSDMap download = (OSDMap)map;
if (
download.ContainsKey("download_count") &&
download.ContainsKey("created_at") &&
download.ContainsKey("description") &&
download.ContainsKey("url") &&
download.ContainsKey("html_url") &&
download.ContainsKey("size") &&
download.ContainsKey("name") &&
download.ContainsKey("content_type") &&
download.ContainsKey("id") &&
download["content_type"].AsString() == ".zip" &&
Regex.IsMatch(download["name"].ToString(), m_regexRelease)
)
{
Match matches = Regex.Match(download["name"].ToString(), m_regexRelease);
releases[new Version(matches.Groups[1].ToString())] = download;
}
}
}
if (releases.Count < 1)
{
ErrorMsg("No releases found");
return;
}
KeyValuePair<Version, OSDMap> latest = releases.OrderByDescending(kvp => kvp.Key).First();
if (latest.Key <= new Version(VersionInfo.VERSION_NUMBER))
{
InfoMsg("You are already using a newer version, no updated is necessary.");
return;
}
DialogResult result = MessageBox.Show("A new version of Aurora has been released, version " + latest.Key.ToString() + " (" + latest.Value["description"] + ")" + ", do you want to download the update?", "Aurora Update", MessageBoxButtons.YesNo);
if (result == DialogResult.Yes)
{
Utilities.DownloadFile(latest.Value["html_url"], "Updates" + System.IO.Path.DirectorySeparatorChar + "AuroraVersion" + latest.Key.ToString() + ".zip");
MessageBox.Show(string.Format("Downloaded to {0}, exiting for user to upgrade.", "Updates" + System.IO.Path.DirectorySeparatorChar + "AuroraVersion" + latest.Key.ToString() + ".zip"), "Aurora Update");
Environment.Exit(0);
}
updateConfig.Set("LatestRelease", latest.Key.ToString());
updateConfig.ConfigSource.Save();
}
catch
{
}
}