本文整理汇总了C#中SortedDictionary.TryGetValue方法的典型用法代码示例。如果您正苦于以下问题:C# SortedDictionary.TryGetValue方法的具体用法?C# SortedDictionary.TryGetValue怎么用?C# SortedDictionary.TryGetValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SortedDictionary
的用法示例。
在下文中一共展示了SortedDictionary.TryGetValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Search
public static string[] Search(String[] token, String txt, out Byte distance)
{
if (txt.Length > 0)
{
Byte bestKey = 255;
SortedDictionary<Byte, List<string>> matches = new SortedDictionary<byte, List<string>>();
Docking.Tools.ITextMetric tm = new Docking.Tools.Levenshtein(50);
foreach(string s in token)
{
Byte d = tm.distance(txt, s);
if (d <= bestKey) // ignore worse matches as previously found
{
bestKey = d;
List<string> values;
if (!matches.TryGetValue(d, out values))
{
values = new List<string>();
matches.Add(d, values);
}
if (!values.Contains(s))
values.Add(s);
}
}
if (matches.Count > 0)
{
List<string> result = matches[bestKey];
distance = bestKey;
return result.ToArray();
}
}
distance = 0;
return null;
}
示例2: getMaxChannels
public int getMaxChannels(int[] from, int[] to, int totalUnits)
{
SortedDictionary<int, int> dictionary = new SortedDictionary<int, int>();
for(int i = 0; i < from.Length; i++)
{
int n = 0;
dictionary.TryGetValue(from[i], out n);
dictionary[from[i]] = n + 1;
n = 0;
dictionary.TryGetValue(to[i], out n);
dictionary[to[i]] = n - 1;
}
if (dictionary[0] == 0)
return 0;
int height = 0;
int channels = int.MaxValue;
foreach(KeyValuePair<int, int> pair in dictionary)
{
if(pair.Key < totalUnits)
{
height += pair.Value;
channels = Math.Min(channels, height);
}
}
return channels;
}
示例3: GetPostsPerMonth
private static SortedDictionary<DateTime, int> GetPostsPerMonth()
{
lock (_SyncRoot)
{
SortedDictionary<DateTime, int> months = HttpRuntime.Cache[CacheKey] as SortedDictionary<DateTime, int>;
if (months == null)
{
months = new SortedDictionary<DateTime, int>();
// let dictionary expire after 1 hour
HttpRuntime.Cache.Insert(CacheKey, months, null, DateTime.Now.AddHours(CacheTimeoutInHours), Cache.NoSlidingExpiration);
foreach (Post post in Post.Posts)
{
if (post.IsVisibleToPublic)
{
DateTime month = new DateTime(post.DateCreated.Year, post.DateCreated.Month, 1);
int count;
// if the date is not in the dictionary, count will be set to 0
months.TryGetValue(month, out count);
++count;
months[month] = count;
}
}
}
return months;
}
}
示例4: Execute
public IResponse Execute(ICruiseRequest request)
{
var velocityContext = new Hashtable();
this.translations = Translations.RetrieveCurrent();
var projectStatus = farmService.GetProjectStatusListAndCaptureExceptions(request.RetrieveSessionToken());
var urlBuilder = request.UrlBuilder;
var category = request.Request.GetText("Category");
var gridRows = this.projectGrid.GenerateProjectGridRows(projectStatus.StatusAndServerList, BaseActionName,
ProjectGridSortColumn.Category, true,
category, urlBuilder,this.translations);
var categories = new SortedDictionary<string, CategoryInformation>();
foreach (var row in gridRows)
{
var rowCategory = row.Category;
CategoryInformation categoryRows;
if (!categories.TryGetValue(rowCategory, out categoryRows))
{
categoryRows = new CategoryInformation(rowCategory);
categories.Add(rowCategory, categoryRows);
}
categoryRows.AddRow(row);
}
velocityContext["categories"] = categories.Values;
return viewGenerator.GenerateView("CategorizedFarmReport.vm", velocityContext);
}
示例5: Main
public static void Main()
{
var courses = new SortedDictionary<string, List<Student>>();
foreach (string line in File.ReadLines("../.../students.txt"))
{
// Each line represents one student
var fields = line.Split('|').Select(s => s.Trim()).ToArray();
var fname = fields[0];
var lname = fields[1];
var course = fields[2];
// Find the list of students for this course
List<Student> students;
if (!courses.TryGetValue(course, out students))
{
// New course -> create a list of students for it
students = new List<Student>();
courses.Add(course, students);
}
var student = new Student() { FirstName = fname, LastName = lname };
students.Add(student);
}
foreach (var course in courses)
{
Console.WriteLine(
"{0}: {1}",
course.Key,
string.Join(", ", course.Value.OrderBy(s => s.LastName).ThenBy(s => s.FirstName)));
}
}
示例6: CountSmaller
public IList<int> CountSmaller(int[] nums)
{
int[] result = new int[nums.Length];
SortedDictionary<int, List<int>> dict = new SortedDictionary<int, List<int>>();
for (int i = 0; i < nums.Length; i++)
{
List<int> l;
if (!dict.TryGetValue(nums[i], out l))
{
dict.Add(nums[i], l = new List<int>());
}
l.Add(i);
}
SegmentTree tree = new SegmentTree(0, nums.Length - 1);
foreach (var pair in dict)
{
foreach (int pos in pair.Value)
{
result[pos] = tree.CountRange(pos + 1, nums.Length - 1);
}
foreach (int pos in pair.Value)
{
tree.Add(pos);
}
}
return result.ToList();
}
示例7: GetPosition
private Vector2 GetPosition(Identifier512 id, SortedDictionary<Identifier512, Peer> peers)
{
Peer end;
if (!peers.TryGetValue(id, out end))
end = peers.Where(a => a.Key >= id).Select(a => a.Value).FirstOrDefault() ?? peers.Last().Value;
return end.Position;
}
示例8: GenerateListOfAssembliesByRuntime
private static SortedDictionary<Version, SortedDictionary<AssemblyNameExtension, string>> GenerateListOfAssembliesByRuntime(string strongName, GetAssemblyRuntimeVersion getRuntimeVersion, Version targetedRuntime, Microsoft.Build.Shared.FileExists fileExists, GetPathFromFusionName getPathFromFusionName, GetGacEnumerator getGacEnumerator, bool specificVersion)
{
Microsoft.Build.Shared.ErrorUtilities.VerifyThrowArgumentNull(targetedRuntime, "targetedRuntime");
IEnumerable<AssemblyNameExtension> enumerable = getGacEnumerator(strongName);
SortedDictionary<Version, SortedDictionary<AssemblyNameExtension, string>> dictionary = new SortedDictionary<Version, SortedDictionary<AssemblyNameExtension, string>>(ReverseVersionGenericComparer.Comparer);
if (enumerable != null)
{
foreach (AssemblyNameExtension extension in enumerable)
{
string str = getPathFromFusionName(extension.FullName);
if (!string.IsNullOrEmpty(str) && fileExists(str))
{
Version version = VersionUtilities.ConvertToVersion(getRuntimeVersion(str));
if ((version != null) && ((targetedRuntime.CompareTo(version) >= 0) || specificVersion))
{
SortedDictionary<AssemblyNameExtension, string> dictionary2 = null;
dictionary.TryGetValue(version, out dictionary2);
if (dictionary2 == null)
{
dictionary2 = new SortedDictionary<AssemblyNameExtension, string>(AssemblyNameReverseVersionComparer.GenericComparer);
dictionary.Add(version, dictionary2);
}
if (!dictionary2.ContainsKey(extension))
{
dictionary2.Add(extension, str);
}
}
}
}
}
return dictionary;
}
示例9: Main
static void Main()
{
string[] symbol = Console.ReadLine().Split();
IDictionary<string, int> letters =
new SortedDictionary<string, int>();
foreach (string letter in symbol)
{
if (string.IsNullOrEmpty(letter.Trim()))
{
continue;
}
int count;
if (!letters.TryGetValue(letter, out count))
{
count = 0;
}
letters[letter] = count + 1;
}
foreach (KeyValuePair<string, int> letterEntry
in letters)
{
Console.WriteLine(
"{0} -> {1}",
letterEntry.Key, letterEntry.Value);
}
}
示例10: GetWordOccurrenceMap
private static IDictionary<string, int> GetWordOccurrenceMap(
string text)
{
string[] tokens =
text.Split(' ', '.', ',', '-', '?', '!');
IDictionary<string, int> words =
new SortedDictionary<string, int>();
foreach (string word in tokens)
{
if (string.IsNullOrEmpty(word.Trim()))
{
continue;
}
int count;
if (!words.TryGetValue(word, out count))
{
count = 0;
}
words[word] = count + 1;
}
return words;
}
示例11: GetLinkedStructures
public static SortedDictionary<long, List<StructureLink>> GetLinkedStructures(StructureLink[] LinkedStructures)
{
SortedDictionary<long, List<StructureLink>> StructIDToLinks = new SortedDictionary<long, List<StructureLink>>();
foreach (StructureLink link in LinkedStructures)
{
List<StructureLink> SourceIDList = null;
if (!StructIDToLinks.TryGetValue(link.SourceID, out SourceIDList))
{
SourceIDList = new List<StructureLink>();
}
SourceIDList.Add(link);
StructIDToLinks[link.SourceID] = SourceIDList;
List<StructureLink> TargetIDList = null;
if (!StructIDToLinks.TryGetValue(link.TargetID, out TargetIDList))
{
TargetIDList = new List<StructureLink>();
}
TargetIDList.Add(link);
StructIDToLinks[link.TargetID] = TargetIDList;
}
return StructIDToLinks;
}
示例12: GetProcessorThreads
private static CPUID[][] GetProcessorThreads() {
List<CPUID> threads = new List<CPUID>();
for (int i = 0; i < 64; i++) {
try {
threads.Add(new CPUID(i));
} catch (ArgumentOutOfRangeException) { }
}
SortedDictionary<uint, List<CPUID>> processors =
new SortedDictionary<uint, List<CPUID>>();
foreach (CPUID thread in threads) {
List<CPUID> list;
processors.TryGetValue(thread.ProcessorId, out list);
if (list == null) {
list = new List<CPUID>();
processors.Add(thread.ProcessorId, list);
}
list.Add(thread);
}
CPUID[][] processorThreads = new CPUID[processors.Count][];
int index = 0;
foreach (List<CPUID> list in processors.Values) {
processorThreads[index] = list.ToArray();
index++;
}
return processorThreads;
}
示例13: addSignRSA
//RSA签名
private static String addSignRSA(SortedDictionary<string, string> sParaTemp, String rsa_private)
{
string oid_partner;
sParaTemp.TryGetValue ("sign_type", out oid_partner);
Console.WriteLine("进入商户[" + oid_partner + "]MD5加签名");
if (sParaTemp == null)
{
return "";
}
// 生成签名原串
String sign_src = genSignData(sParaTemp);
Console.WriteLine("商户[" + oid_partner + "]加签原串"
+ sign_src);
Console.WriteLine("RSA签名key:" + rsa_private);
try
{
string sign = RSAFromPkcs8.sign(sign_src,rsa_private,"utf-8");
Console.WriteLine("商户[" + oid_partner + "]签名结果"
+ sign);
return sign;
} catch (Exception e)
{
Console.WriteLine("商户[" + oid_partner + "]RSA加签名异常" + e.Message);
return "";
}
}
示例14: Main
static void Main()
{
string[] word = Console.ReadLine().Split();
IDictionary<string, int> words =
new SortedDictionary<string, int>();
foreach (string item in word)
{
if (string.IsNullOrEmpty(item.Trim()))
{
continue;
}
int count;
if (!words.TryGetValue(item, out count))
{
count = 0;
}
words[item] = count + 1;
}
foreach (KeyValuePair<string, int> itemEntry
in words)
{
Console.WriteLine(
"{0} -> {1}",
itemEntry.Key, itemEntry.Value);
}
}
示例15: addSignMD5
//MD5签名
private static String addSignMD5(SortedDictionary<string, string> sParaTemp, String md5_key)
{
string oid_partner;
sParaTemp.TryGetValue ("sign_type", out oid_partner);
Console.WriteLine("进入商户[" + oid_partner + "]MD5加签名");
if (sParaTemp == null)
{
return "";
}
// 生成签名原串
String sign_src = genSignData(sParaTemp);
Console.WriteLine("商户[" + oid_partner + "]加签原串"
+ sign_src);
Console.WriteLine("MD5签名key:" + md5_key);
sign_src += "&key=" + md5_key;
try
{
string sign = Md5Algorithm.getInstance().md5Digest(
Encoding.UTF8.GetBytes (sign_src));
Console.WriteLine("商户[" + oid_partner + "]签名结果"
+ sign);
return sign;
} catch (Exception e)
{
Console.WriteLine("商户[" + oid_partner
+ "] MD5加签名异常" + e.Message);
return "";
}
}