本文整理汇总了C#中SortedDictionary.Select方法的典型用法代码示例。如果您正苦于以下问题:C# SortedDictionary.Select方法的具体用法?C# SortedDictionary.Select怎么用?C# SortedDictionary.Select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SortedDictionary
的用法示例。
在下文中一共展示了SortedDictionary.Select方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SqlCallProcedureInfo
public SqlCallProcedureInfo(MethodInfo method, ISerializationTypeInfoProvider typeInfoProvider)
{
if (method == null) {
throw new ArgumentNullException("method");
}
if (typeInfoProvider == null) {
throw new ArgumentNullException("typeInfoProvider");
}
SqlProcAttribute procedure = GetSqlProcAttribute(method);
schemaName = procedure.SchemaName;
name = procedure.Name;
timeout = procedure.Timeout;
deserializeReturnNullOnEmptyReader = procedure.DeserializeReturnNullOnEmptyReader;
deserializeRowLimit = procedure.DeserializeRowLimit;
deserializeCallConstructor = procedure.DeserializeCallConstructor;
SortedDictionary<int, SqlCallParameterInfo> sortedParams = new SortedDictionary<int, SqlCallParameterInfo>();
outArgCount = 0;
foreach (ParameterInfo parameterInfo in method.GetParameters()) {
if ((parameterInfo.GetCustomAttributes(typeof(SqlNameTableAttribute), true).Length > 0) || (typeof(XmlNameTable).IsAssignableFrom(parameterInfo.ParameterType))) {
if (xmlNameTableParameter == null) {
xmlNameTableParameter = parameterInfo;
}
} else {
SqlCallParameterInfo sqlParameterInfo = new SqlCallParameterInfo(parameterInfo, typeInfoProvider, ref outArgCount);
sortedParams.Add(parameterInfo.Position, sqlParameterInfo);
}
}
parameters = sortedParams.Select(p => p.Value).ToArray();
returnTypeInfo = typeInfoProvider.GetSerializationTypeInfo(method.ReturnType);
if ((procedure.UseReturnValue != SqlReturnValue.Auto) || (method.ReturnType != typeof(void))) {
useReturnValue = (procedure.UseReturnValue == SqlReturnValue.ReturnValue) || ((procedure.UseReturnValue == SqlReturnValue.Auto) && (typeInfoProvider.TypeMappingProvider.GetMapping(method.ReturnType).DbType == SqlDbType.Int));
}
}
示例2: Solve
public long Solve()
{
var primes = new Prime((int)DivisoNumbers);
var sortedPrimes = new SortedDictionary<long, PrimeDivisors>();
foreach (var prime in primes.PrimeList)
{
sortedPrimes.Add(prime, new PrimeDivisors(prime));
}
while (true)
{
var minkey = sortedPrimes.Keys.First();
var maxKey = sortedPrimes.Keys.Last();
var minValue = sortedPrimes[minkey];
var newKey = minkey * minkey;
if (newKey > maxKey)
{
break;
}
sortedPrimes.Add(newKey, minValue.UpdatePower());
sortedPrimes.Remove(minkey);
sortedPrimes.Remove(maxKey);
}
return sortedPrimes.Select(
primeDivisorse => (long)Math.Pow(primeDivisorse.Value.Prime, primeDivisorse.Value.Power) % Modulo
).Aggregate(
1L, (current, coefficient) => (current * coefficient) % Modulo
);
}
示例3: Main
static void Main(string[] args)
{
var count = int.Parse(Console.ReadLine());
var officeStuff = new SortedDictionary<string, Dictionary<string, int>>();
for (int i = 0; i < count; i++)
{
var parameters = Regex.Match(
Console.ReadLine(),
@"^\|(?<company>\w+).+?(?<amount>\d+).+?(?<product>\w+)\|$");
var company = parameters.Groups["company"].Value;
var product = parameters.Groups["product"].Value;
var amount = int.Parse(parameters.Groups["amount"].Value);
if (!officeStuff.ContainsKey(company))
{
officeStuff.Add(company, new Dictionary<string, int>());
}
if (!officeStuff[company].ContainsKey(product))
{
officeStuff[company][product] = 0;
}
officeStuff[company][product] += amount;
}
officeStuff.Select(
pair =>
$"{pair.Key}: {String.Join(", ", pair.Value.Select(anotherPair => $"{anotherPair.Key}-{anotherPair.Value}"))}")
.ToList()
.ForEach(Console.WriteLine);
}
示例4: FindMajorant
private static void FindMajorant(List<int> numbers)
{
var occuarances = new SortedDictionary<int, int>();
foreach (var number in numbers)
{
if (occuarances.ContainsKey(number))
{
occuarances[number]++;
}
else
{
occuarances[number] = 1;
}
}
var majorantChecker = (numbers.Count / 2) + 1;
var majorant = occuarances.Select(x => x).Where(x => x.Value >= majorantChecker);
if (majorant.FirstOrDefault().Equals(default(KeyValuePair<int, int>)))
{
Console.WriteLine("No majorant");
}
else
{
Console.WriteLine("Majorant {0} -> {1} times of all {2}",
majorant.First().Key, majorant.First().Value, numbers.Count);
}
}
示例5: ReportResult
internal static void ReportResult()
{
Console.WriteLine("** Printing results of the perf run (C#) **");
var allMedianCosts = new SortedDictionary<string, long>();
foreach (var perfResultItem in PerfResults)
{
var perfResult = perfResultItem.Value;
var runTimeInSeconds = perfResult.Select(x => (long)x.TotalSeconds);
//multiple enumeration happening - ignoring that for now
var max = runTimeInSeconds.Max();
var min = runTimeInSeconds.Min();
var avg = (long)runTimeInSeconds.Average();
var median = GetMedianValue(runTimeInSeconds);
Console.WriteLine(
"** Execution time for {0} in seconds. Min={1}, Max={2}, Average={3}, Median={4}, Number of runs={5}, Individual execution duration=[{6}] **",
perfResultItem.Key, min, max, avg, median, runTimeInSeconds.Count(), string.Join(", ", runTimeInSeconds));
allMedianCosts[perfResultItem.Key] = median;
}
Console.WriteLine("** *** **");
Console.WriteLine("{0} {1} C# version: Run count = {2}, all median time costs[{3}] : {4}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
Regex.Replace(TimeZone.CurrentTimeZone.StandardName, @"(\w)\S*\s*", "$1"),
PerfResults.First().Value.Count, allMedianCosts.Count, string.Join("; ", allMedianCosts.Select(kv => kv.Key + "=" + kv.Value)));
}
示例6: CompositeCommand
public CompositeCommand(CommandContext context, Dictionary<string, JToken> commands)
{
var dictionary = new SortedDictionary<CommandType, JToken>();
foreach (var pair in commands)
{
CommandType subCommandType;
if (Enum.TryParse(pair.Key, true, out subCommandType))
{
if (dictionary.ContainsKey(subCommandType))
{
Logger.Log(LogLevel.Warning, $"{subCommandType} is defined in config file for several times, the first config is used. NOTE that key is case insensitive.");
}
else
{
dictionary.Add(subCommandType, pair.Value);
}
}
else
{
Logger.Log(LogLevel.Info, $"\"{pair.Key}\" is not a valid command currently supported, ignored.");
}
}
// Order is now defined in SubCommandType
Commands = dictionary.Select(s => CommandFactory.GetCommand(s.Key, s.Value, context)).ToList();
}
示例7: BinaryTreeMustSortTheSameAsSortedDictionary
public void BinaryTreeMustSortTheSameAsSortedDictionary()
{
// Arrange
var asm = Assembly.GetExecutingAssembly();
var importer = new Importer(asm.GetManifestResourceStream("ClientImport.Tests.records.txt"), ',');
var dictionary = new SortedDictionary<string, IPerson>();
var tree = new BinarySearchTree<string, IPerson>();
//Act
importer.Data
.ToList()
.ForEach(record =>
{
var person = new Person
{
FirstName = record.FirstName,
Surname = record.Surname,
Age = Convert.ToInt16(record.Age)
};
var key = PersonRepository.BuildKey(person, SortKey.SurnameFirstNameAge);
if (tree.Find(key) == null)
tree.Add(key, person);
}
);
tree
.ToList()
.Shuffle() //Shuffle result from binary tree, to test sorting
.ForEach(r => dictionary.Add(PersonRepository.BuildKey(r.KeyValue.Value, SortKey.SurnameFirstNameAge), r.KeyValue.Value));
var expected = dictionary.Select(r => r.Value).ToList();
var actual = tree.Select(n => n.KeyValue.Value).ToList();
// Assert
CollectionAssert.AreEqual(expected, actual);
}
示例8: GetData
public List<SpreadPeriod> GetData()
{
var results = new SortedDictionary<long, SpreadPeriod>();
this.AddValues(results, this.max, (x, y) => x.max = y);
this.AddValues(results, this.min, (x, y) => x.min = y);
this.AddValues(results, this.avg, (x, y) => x.avg = y);
double lastMax = 0;
double lastMin = 0;
double lastAvg = 0;
foreach (var period in results.Select(pair => pair.Value))
{
if (period.max == 0)
{
period.max = lastMax;
}
if (period.min == 0)
{
period.min = lastMin;
}
if (period.avg == 0)
{
period.avg = lastAvg;
}
lastMax = period.max;
lastMin = period.min;
lastAvg = period.avg;
}
return results.Values.ToList();
}
示例9: Build
private static string Build(Map properties)
{
var sortedProperties = new SortedDictionary<string, object>(properties);
var urlEncoded = sortedProperties
.Select(entry => $"{RequestHelper.UrlEncode(entry.Key)}={RequestHelper.UrlEncode(entry.Value.ToString())}")
.Join("&");
return urlEncoded;
}
示例10: CreateMd5Sign
/// <summary>
/// 摘要:
/// 计算MD5签名值.
/// </summary>
/// <param name="input">输入参数集</param>
/// <param name="key">密钥</param>
public static string CreateMd5Sign(IDictionary<string, string> input, string key)
{
ThrowHelper.ThrowNullArgument(input, nameof(input));
ThrowHelper.ThrowNullOrEmptyArgument(key, nameof(key));
var data = new SortedDictionary<string, string>(input);
var pairs = data.Select(pair => $"{pair.Key}={pair.Value}");
var source = string.Join("&", pairs);
return Meow.Security.SecurityUtils.CalculateMD5Hash($"{source}&key={key}", "X2");
}
示例11: MakeSign
public string MakeSign(SortedDictionary<string,string> dic)
{
var urlFormatString = string.Join("&", dic.Select(d => d.Key + "=" + d.Value));
//MD5加密
var md5 = MD5.Create();
var bs = md5.ComputeHash(Encoding.UTF8.GetBytes(urlFormatString));
var sb = new StringBuilder();
foreach (byte b in bs)
{
sb.Append(b.ToString("x2"));
}
//所有字符转为大写
return sb.ToString().ToUpper();
}
示例12: CreateAuthorizationHeaderParameter
private static string CreateAuthorizationHeaderParameter(
string url,
Dictionary<string, string> parameters,
string oauth_consumer_key,
string oauth_consumer_secret,
string oauth_token,
string oauth_token_secret,
string method = "GET"
)
{
var dictionary = new SortedDictionary<string, string>
{
{"oauth_version", "1.0"},
{"oauth_consumer_key", oauth_consumer_key},
{"oauth_nonce", Convert.ToBase64String(new ASCIIEncoding().GetBytes(DateTime.Now.Ticks.ToString()))},
{"oauth_signature_method", "HMAC-SHA1"},
{"oauth_timestamp", Convert.ToInt64((DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds).ToString()},
{"oauth_token", oauth_token}
};
foreach (var p in parameters)
{
dictionary.Add(p.Key, p.Value);
}
string baseString =
method.ToUpper() +
"&" +
Uri.EscapeDataString(url) +
"&" +
Uri.EscapeDataString(string.Join("&", dictionary.Select(x => string.Format("{0}={1}", Uri.EscapeDataString(x.Key), Uri.EscapeDataString(x.Value)))));
string signingKey = Uri.EscapeDataString(oauth_consumer_secret) + "&" + Uri.EscapeDataString(oauth_token_secret);
var hasher = new HMACSHA1(new ASCIIEncoding().GetBytes(signingKey));
string signatureString = Convert.ToBase64String(hasher.ComputeHash(new ASCIIEncoding().GetBytes(baseString)));
string authorizationHeaderParams = "";
authorizationHeaderParams += "OAuth ";
authorizationHeaderParams += "oauth_consumer_key=" + "\"" + Uri.EscapeDataString(dictionary["oauth_consumer_key"]) + "\", ";
authorizationHeaderParams += "oauth_nonce=" + "\"" + Uri.EscapeDataString(dictionary["oauth_nonce"]) + "\", ";
authorizationHeaderParams += "oauth_signature=" + "\"" + Uri.EscapeDataString(signatureString) + "\", ";
authorizationHeaderParams += "oauth_signature_method=" + "\"" + Uri.EscapeDataString(dictionary["oauth_signature_method"]) + "\", ";
authorizationHeaderParams += "oauth_timestamp=" + "\"" + Uri.EscapeDataString(dictionary["oauth_timestamp"]) + "\", ";
authorizationHeaderParams += "oauth_token=" + "\"" + Uri.EscapeDataString(dictionary["oauth_token"]) + "\", ";
authorizationHeaderParams += "oauth_version=" + "\"" + Uri.EscapeDataString(dictionary["oauth_version"]) + "\"";
return authorizationHeaderParams;
}
示例13: CalculateStats
private static string CalculateStats(SortedDictionary<string, int[]> dragonsOfType)
{
var count = dragonsOfType.Count;
var typeStats = new[] { 0.0, 0.0, 0.0 };
foreach (var currentDragonStats in dragonsOfType.Select(dragon => dragon.Value))
{
for (int i = 0; i < currentDragonStats.Length; i++)
{
typeStats[i] += currentDragonStats[i];
}
}
return $"{typeStats[0] / count:f2}/{typeStats[1] / count:f2}/{typeStats[2] / count:f2}";
}
示例14: DictionaryToString
public string DictionaryToString(SortedDictionary<string, object> dictionary)
{
if (dictionary == null)
return "";
StringBuilder buffer = new StringBuilder();
buffer.Append("{");
if (dictionary == null || dictionary.Count == 0)
buffer.Append(" ");
else
{
buffer.Append(string.Join(", ", dictionary.Select(e => string.Format("{0} = {1}", e.Key, e.Value)).ToArray()));
}
buffer.Append("}");
return buffer.ToString();
}
示例15: DisplayError
protected override bool DisplayError(Exception exception)
{
if (exception == null)
return true;
List<string> errors = new List<string>();
errors.Add(ErrorReport.GetExceptionText(exception));
errors.Add("Standard ErrorReport properties for above exception:");
var errorProperties = new SortedDictionary<string, string>(ErrorReport.GetStandardProperties());
errors.AddRange(errorProperties.Select(property => String.Format("{0}: {1}", property.Key, property.Value)));
/* Commented out: Adding platform properties is unnecessary since ErrorReport's OSVersion property will tell us more anyway
errors.Add("Platform properties for above exception:");
foreach (PropertyInfo property in typeof(Platform).GetProperties())
{
errors.Add(String.Format("{0}: {1}", property.Name, property.GetValue(typeof(Platform), null)));
}
*/
_logger.LogMany(SyslogPriority.Error, errors);
return true;
}