本文整理汇总了C#中SortedDictionary.OrderBy方法的典型用法代码示例。如果您正苦于以下问题:C# SortedDictionary.OrderBy方法的具体用法?C# SortedDictionary.OrderBy怎么用?C# SortedDictionary.OrderBy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SortedDictionary
的用法示例。
在下文中一共展示了SortedDictionary.OrderBy方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main()
{
StreamReader reader = new StreamReader(@"../../../students.txt");
SortedDictionary<string, OrderedBag<Student>> courses = new SortedDictionary<string, OrderedBag<Student>>();
using (reader)
{
string line;
while ((line = reader.ReadLine()) != null)
{
string[] info = line.Split(new char[] { ' ', '|' }, StringSplitOptions.RemoveEmptyEntries);
if (courses.ContainsKey(info[2]))
{
courses[info[2]].Add(new Student(info[0], info[1]));
}
else
{
courses[info[2]] = new OrderedBag<Student> { new Student(info[0], info[1]) };
}
}
foreach (var item in courses.OrderBy(x=> x.Key))
{
var students = item.Value;
Console.Write("{0}: ",item.Key);
foreach (var student in students)
{
Console.Write(student.FirstName +" "+ student.LastName+", ");
}
Console.WriteLine();
}
}
}
示例2: Main
static void Main()
{
using (StreamReader reader = new StreamReader("../../input.txt"))
{
var text = reader.ReadToEnd();
var regex = new Regex(@"\w+", RegexOptions.Multiline);
var words = regex.Matches(text);
var wordsOccurences = new SortedDictionary<string, int>();
foreach (var word in words)
{
var wordToLower = word.ToString().ToLower();
if (wordsOccurences.ContainsKey(wordToLower))
{
wordsOccurences[wordToLower]++;
}
else
{
wordsOccurences[wordToLower] = 1;
}
}
var orderedWordsByOcurences = wordsOccurences
.OrderBy(w => w.Value);
foreach (var word in orderedWordsByOcurences)
{
Console.WriteLine("{0, -5} => {1}", word.Key, word.Value);
}
}
}
示例3: Main
static void Main(string[] args)
{
string text = "This is the TEXT. Text, text, text - THIS TEXT! Is this the text?";
text = text.ToLower();
string[] words = text.Split(new char[] { ' ', '.', ',', '-', '!', '?' },
StringSplitOptions.RemoveEmptyEntries);
IDictionary<string, int> wordOcurances = new SortedDictionary<string, int>();
for (int i = 0; i < words.Length; i++)
{
if (wordOcurances.ContainsKey(words[i]))
{
wordOcurances[words[i]]++;
}
else
{
wordOcurances.Add(words[i], 1);
}
}
var orderedWords = wordOcurances.OrderBy(x => x.Value);
foreach (var pair in orderedWords)
{
Console.WriteLine("{0} -> {1}", pair.Key, pair.Value);
}
}
示例4: GetEnumSortOrder
public static Enum[] GetEnumSortOrder(this System.Array value)
{
var coll = new SortedDictionary<Enum, int>();
foreach (Enum @enum in value)
{
var order = @enum.GetEnumSortOrder();
coll.Add(@enum, order);
}
return coll.OrderBy(p => p.Value).Select(p => p.Key).ToArray();
}
示例5: CountWordsInTextFile
public void CountWordsInTextFile(string path)
{
var reader = new StreamReader(path);
var words = new SortedDictionary<string, int>();
using (reader)
{
var line = reader.ReadLine().ToLower();
while (line != null)
{
var length = line.Length;
var word = new StringBuilder();
for (int i = 0; i < length; i++)
{
var symbol = line[i];
if (char.IsLetter(symbol))
{
word.Append(symbol);
}
else
{
if (word.Length > 0)
{
var wordAsString = word.ToString();
if (!words.ContainsKey(wordAsString))
{
words.Add(wordAsString, 1);
}
else
{
words[wordAsString] += 1;
}
}
word.Clear();
}
}
line = reader.ReadLine();
}
}
var sortedWordsByValue = words.OrderBy(w => w.Value).ToList();
foreach (var word in sortedWordsByValue)
{
Console.WriteLine(word.Key + " -> " + word.Value);
}
Console.WriteLine();
}
示例6: Main
public static void Main()
{
//Write a program that counts how many times each word from given text file words.txt appears in it.The character casing differences should be ignored.The result words should be ordered by their number of occurrences in the text. Example:
//This is the TEXT.Text, text, text – THIS TEXT!Is this the text?
string text = string.Empty;
try
{
using (StreamReader reader = new StreamReader("../../input.txt"))
{
text = reader.ReadToEnd();
Console.WriteLine(text);
}
}
catch (Exception e)
{
Console.WriteLine("The file could not be read:");
Console.WriteLine(e.Message);
}
string[] arr = text.Split(new char[] { ',', ' ', '!', '?', '-', '.' }, StringSplitOptions.RemoveEmptyEntries);
IDictionary<string, int> dictionary = new SortedDictionary<string, int>();
for (int i = 0; i < arr.Length; i++)
{
int count = 1;
if (dictionary.ContainsKey(arr[i].ToLower()))
{
count = dictionary[arr[i].ToLower()] + 1;
}
dictionary[arr[i].ToLower()] = count;
}
var words = dictionary.OrderBy(x => x.Value);
foreach (var pair in words)
{
Console.WriteLine("{0} -> {1} times", pair.Key, pair.Value);
}
}
示例7: Main
public static void Main()
{
var streamReader = new StreamReader("../../words.txt");
using (streamReader)
{
var line = streamReader.ReadLine();
var wordsAndOccurences = new SortedDictionary<string, int>();
while (line != null)
{
////split by all kind of punctuation
var words = line
.Split(new char[] { ',', ' ', '.', '?', '!', '>', '<', '(', ')', '-' }, StringSplitOptions.RemoveEmptyEntries)
.ToArray();
foreach (var word in words)
{
if (!wordsAndOccurences.ContainsKey(word.ToLower()))
{
wordsAndOccurences.Add(word.ToLower(), 1);
}
else
{
wordsAndOccurences[word.ToLower()]++;
}
}
var sortedCollection = wordsAndOccurences.OrderBy(p => p.Value);
foreach (var pair in sortedCollection)
{
Console.WriteLine("{0} -> {1}", pair.Key, pair.Value);
}
line = streamReader.ReadLine();
}
}
}
示例8: CreateURLParamString
private string CreateURLParamString(SortedDictionary<string, string> dicArray, EnumAliPayType type = EnumAliPayType.Website)
{
StringBuilder prestr = new StringBuilder();
foreach (KeyValuePair<string, string> temp in dicArray.OrderBy(o => o.Key))
{
if (type == EnumAliPayType.Mobile)
prestr.Append(temp.Key + "=\"" + temp.Value + "\"&");
else
prestr.Append(temp.Key + "=" + temp.Value + "&");
}
int nLen = prestr.Length;
prestr.Remove(nLen - 1, 1);
return prestr.ToString();
}
示例9: GetVideoUrl
public override string GetVideoUrl(VideoInfo video)
{
string data = GetWebData(video.VideoUrl);
JObject jsonVideos = JObject.Parse(data);
JArray streams = (JArray)jsonVideos.SelectToken("authorization_data").First().First().SelectToken("streams");
string previous_master_m3u8_url = "";
foreach (JToken stream in streams)
{
if ("akamai_hd2_vod_hls".Equals((string)stream.SelectToken("delivery_type")))
{
previous_master_m3u8_url = Base64Decode((string)stream.SelectToken("url.data"));
break;
}
}
if (!"".Equals(previous_master_m3u8_url))
{
string options_data = GetWebData(previous_master_m3u8_url);
string[] options = options_data.Split('\n');
SortedDictionary<string, string> playbackOptions = new SortedDictionary<string, string>();
for (int i = 1; i < options.Length; i = i + 2)
{
string[] features = options[i].Split(',');
string resolution = "";
int bandwidth = 0;
foreach (string feature in features)
{
if (feature.StartsWith("BANDWIDTH"))
{
bandwidth = int.Parse(feature.Split('=')[1]) / 1024;
}
else if (feature.StartsWith("RESOLUTION"))
{
resolution = feature.Split('=')[1];
}
}
string nm = string.Format("{0} {1}K", resolution, bandwidth);
string url = options[i + 1];
playbackOptions.Add(nm, url);
}
video.PlaybackOptions = new Dictionary<string, string>();
foreach (var item in playbackOptions.OrderBy(i => int.Parse(i.Key.Split(' ')[1].Split('K')[0])))
{
video.PlaybackOptions.Add(item.Key, item.Value);
}
}
if (video.PlaybackOptions.Count == 0)
{
return "";// if no match, return empty url -> error
}
else if (video.PlaybackOptions.Count == 1)
{
string resultUrl = video.PlaybackOptions.Last().Value;
video.PlaybackOptions = null;// only one url found, PlaybackOptions not needed
return resultUrl;
}
else
{
return video.PlaybackOptions.Last().Value;
}
}
示例10: Main
// Methods
private static void Main(string[] args)
{
FileStream statusFile = new FileStream("status_dump.txt", FileMode.OpenOrCreate, FileAccess.Write);
StreamWriter statusWriter = new StreamWriter(statusFile);
int count = 0;
try
{
WebResponseBuilder responseBuilder = new WebResponseBuilder();
string twitter_api_username = ConfigurationManager.AppSettings["twitter_user"];
string twitter_api_password = ConfigurationManager.AppSettings["twitter_pass"];
responseBuilder.UseCGICredentials(twitter_api_username, twitter_api_password);
TwitterStreamStatusProvider provider = new TwitterStreamStatusProvider(responseBuilder);
provider.YieldThisMany = NUM_STATUSES_TO_PULL;
Console.Out.WriteLine("About to start reading from twitter - up to " + NUM_STATUSES_TO_PULL + " statuses.");
//expensive operation..
EnglishStatusProvider englishProvider = new EnglishStatusProvider(provider, "english_data");
SortedDictionary<long, int> userMsgCounts = new SortedDictionary<long, int>();
SortedDictionary<long, string> usernameLookup = new SortedDictionary<long, string>();
foreach (TwitterStatus status in englishProvider.GetMessages())
{
string username = status.user.screen_name;
long user_id = status.user.id;
if (!usernameLookup.ContainsKey(user_id))
{
usernameLookup.Add(user_id, username);
userMsgCounts.Add(user_id, 1);
}
else
{
userMsgCounts[user_id] += 1;
}
string text = status.text.Replace("|", " ");
text = text.Replace("\r\n", " ").Replace("\n", " ").Replace("\r", " ");
statusWriter.WriteLine(string.Concat(new object[] { user_id, "|", username, "|", text }));
//Console.Out.WriteLine(string.Concat(new object[] { user_id, "|", username, "|", text }));
if (count++ > WRITE_OUT_USERS_EVERY)
{
count = 0;
FileStream userFile = new FileStream("users.txt", FileMode.Create, FileAccess.Write);
using (StreamWriter userWriter = new StreamWriter(userFile))
{
foreach (KeyValuePair<long, int> userMsgCount in userMsgCounts.OrderBy(key => key.Value))
{
user_id = userMsgCount.Key;
username = usernameLookup[user_id];
int msgCount = userMsgCount.Value;
userWriter.WriteLine(string.Concat(new object[] { msgCount, " messages|", user_id, "|", username }));
}
userWriter.Flush();
userWriter.Close();
Console.Out.WriteLine("Done writing out " + userMsgCounts.Count + " matching users");
}
}
statusWriter.Flush();
}
}
finally
{
statusWriter.Flush();
statusWriter.Close();
}
}
示例11: btnFindDuplicateSolutions_Click
/// <summary>
/// Vytvoří slovník kde v klíči je název projektů a v hodnotě pak cesty k projektům, které měli stejný název.
/// Nic nemaže
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnFindDuplicateSolutions_Click(object sender, RoutedEventArgs e)
{
lbResults.Items.Clear();
List<string> projeteNazvyReseni = new List<string>();
List<SolutionFolder> solutions = new List<SolutionFolder>();
foreach (FoldersWithSolutions fws in fwss)
{
solutions.AddRange( fws.Solutions());
}
Dictionary<string, List<SolutionFolder>> duplicateSolutions = new Dictionary<string, List<SolutionFolder>>();
foreach (var item in solutions)
{
if (projeteNazvyReseni.Contains(item.nameSolutionWithoutDiacritic))
{
continue;
}
else
{
projeteNazvyReseni.Add(item.nameSolutionWithoutDiacritic);
foreach (var item2 in solutions)
{
if (item2.nameSolutionWithoutDiacritic == item.nameSolutionWithoutDiacritic)
{
if (!duplicateSolutions.ContainsKey(item2.nameSolutionWithoutDiacritic))
{
List<SolutionFolder> ff = new List<SolutionFolder>();
ff.Add(item2);
duplicateSolutions.Add(item2.nameSolutionWithoutDiacritic, ff);
}
else
{
duplicateSolutions[item2.nameSolutionWithoutDiacritic].Add(item2);
}
}
}
}
}
int celkemDuplikatnichReseni = 0;
SortedDictionary<string, List<SolutionFolder>> serazeneProjekty = new SortedDictionary<string, List<SolutionFolder>>();
foreach (var item in duplicateSolutions)
{
if (item.Value.Count > 1)
{
//lbResults.Items.Add(sp);
List<SolutionFolder> sfs = new List<SolutionFolder>();
foreach (var value in item.Value)
{
//lbResults.Items.Add(value);
sfs.Add(value);
celkemDuplikatnichReseni++;
}
serazeneProjekty.Add(item.Key, sfs);
}
}
var serazeneProjekty2 = serazeneProjekty.OrderBy(d => (d.Key));
foreach (var item in serazeneProjekty2)
{
Grid sp = new Grid();
//sp.Width = new GridLength(1, GridUnitType.Star).Value;
TextBlock tb = new TextBlock();
tb.Text = item.Key;
tb.FontSize = 20;
//tb.Width = new GridLength(1, GridUnitType.Star).Value;
tb.Background = new SolidColorBrush(Colors.Gray);
sp.Children.Add(tb);
lbResults.Items.Add(sp);
foreach (var value in item.Value)
{
AddToLbResult(value);
}
}
txtStatus.Text = "Nalezeno celkem " + celkemDuplikatnichReseni + " duplikátních řešení.";
}
示例12: isPaymentValid
public bool isPaymentValid(string shaOUTPassPhrase, NameValueCollection nvc)
{
//Set the default value
bool isValid = false;
//Get all the default ogone parameters
List<string> lsOgoneResponseValues = this.getOgoneResponseValues();
//Create a dictionary to store all the ogone response values from the application
SortedDictionary<string, string> qs = new SortedDictionary<string, string>();
//Loop over the querystring values
foreach (KeyValuePair<string, string> kvp in nvc.AllKeys.ToDictionary(k => k, k => nvc[k]))
{
//Check if the querystring key in an ogone response value
if (lsOgoneResponseValues.Contains(kvp.Key.ToString().ToUpper()))
{
//If the value is empty do not add it
if (!kvp.Value.ToString().Equals(""))
{
//if yes, add it to the dictionary
qs.Add(kvp.Key.ToString().ToUpper(), kvp.Value.ToString());
}
}
}
//Sort the list
qs.OrderBy(k => k.Key);
if (this.getShaSign(qs, shaOUTPassPhrase).ToUpper().Equals(nvc["SHASIGN"].ToUpper()))
{
isValid = true;
}
return isValid;
}