本文整理汇总了C#中System.Collections.Dictionary.Max方法的典型用法代码示例。如果您正苦于以下问题:C# Dictionary.Max方法的具体用法?C# Dictionary.Max怎么用?C# Dictionary.Max使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Dictionary
的用法示例。
在下文中一共展示了Dictionary.Max方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InferCellTypeForColumn
/// <summary>
/// Attempts to infer the type of cells present by obtaining
/// the first 30 cells and counting the possible types.
/// </summary>
/// <returns>The cell type for column.</returns>
/// <param name="column">The column to use.</param>
public Type InferCellTypeForColumn(string column)
{
string startRow = "1";
string endRow = "30";
ICollection<ICell> cells = _dataSource.GetCells (column, startRow, endRow);
IDictionary<Type, int> typeCounts = new Dictionary<Type, int>();
foreach (ICell cell in cells) {
int oldValue = 0;
if (typeCounts.TryGetValue(cell.GetType(), out oldValue)) {
typeCounts.Add(cell.GetType(), oldValue + 1);
} else {
typeCounts.Add (cell.GetType(), 0);
}
}
int max = typeCounts.Max (k => k.Value);
return typeCounts.Where(k => k.Value.Equals(max)).FirstOrDefault().Key;
}
示例2: GetPotentialActions
private List<KeyValuePair<AiAction, int>> GetPotentialActions()
{
var potential = new Dictionary<AiAction, int>();
foreach (var t in _actions)
{
int n;
if (t.Trigger(out n))
potential.Add(t, n);
}
if (potential.Count == 0)
return new List<KeyValuePair<AiAction, int>>();
var max = potential.Max(kvp => kvp.Value);
var matches = potential.Where(kvp => kvp.Value == max).ToList();
return matches;
}
示例3: BuildReport
/// <summary>
/// Builds the report.
/// </summary>
/// <param name="reportDocument">The report document.</param>
public void BuildReport(ICustomReport reportDocument)
{
var currentReport = reportDocument.Reports.First();
SetIdentity(currentReport);
//_originalPageHeaderHeight = ((PageHeaderSection) currentReport.Items["pageHeader"]).Height;
//This report parameter holds the current template system name.
_processName = currentReport.ReportParameters["processName"].Value.ToString();
//This report parameter holds the currently visible columns of the grid and in what order they're in
var cols = currentReport.ReportParameters["columns"].Value.ToString();
var columns = cols.Split(';').ToList();
_columns = new List<ColumnInfo>();
foreach (var col in columns)
{
_columns.Add(new ColumnInfo(col));
}
var groupsStr = currentReport.ReportParameters["groups"].Value.ToString();
_groups = (string.IsNullOrEmpty(groupsStr) ? new string[0] : groupsStr.Split(';')).ToList();
//TODO: Uncomment if needed
// _columns.AddRange(_groups);
if (reportDocument.FitToPage)
{
if (currentReport.GetType().Name.ToLower().Contains("landscape"))
{
FitToPageColumnWidth = Math.Min(1, 10.0 / _columns.Count);
FitToPageColumnCount = (short) Math.Max(10, _columns.Count);
}
if (currentReport.GetType().Name.ToLower().Contains("portrait"))
{
FitToPageColumnWidth = Math.Min(1.1, 7.0 / _columns.Count);
FitToPageColumnCount = (short) Math.Max(7, _columns.Count);
}
currentReport.Width = new Unit(_columns.Count * FitToPageColumnWidth, UnitType.Inch);
}
_groupColumn = currentReport.ReportParameters["groupColumn"].Value.ToString();
var fldList = new List<FieldInfo>(_columns.Count);
var processProperties = new Dictionary<PropertyInfo, string>();
var processType = TheDynamicTypeManager.GetInfoType<IInfoClass>(_processName);
if (processType != null)
{
processProperties = processType.GetAllPropertiesWithPaths();
var properties = processProperties.Where(p => _columns.Any(c=>c.SystemName == p.Value));
foreach (var column in _columns)
{
foreach (var property in properties)
{
if (property.Value == column.SystemName)
{
fldList.Add(new FieldInfo(property.Key, column));
break;
}
}
}
_fieldAttrDict = GetFieldAttributes(processProperties.Select(x => x.Key));
}
if (_fieldAttrDict == null)
_fieldAttrDict = new Dictionary<PropertyInfo, FieldParametres>();
_colDict = new SortedDictionary<int, string[]>();
//Grouping
foreach (var colName in _groups)
{
var group = new Telerik.Reporting.Group();
group.Name = colName;
var groupHeaderSection = new GroupHeaderSection();
var groupFooterSection = new GroupFooterSection();
group.GroupHeader = groupHeaderSection;
group.GroupFooter = groupFooterSection;
var txt = new TextBox();
txt.Style.Font.Size = new Unit(10, UnitType.Point);
txt.Style.Font.Bold = true;
txt.Style.BackgroundColor = Color.FromArgb(255, 225, 225, 225);
txt.Style.TextAlign = HorizontalAlign.Left;
txt.Style.VerticalAlign = VerticalAlign.Middle;
groupHeaderSection.Items.Add(txt);
groupHeaderSection.Height = new Unit(21);
groupHeaderSection.Style.BorderStyle.Default = BorderType.Solid;
groupHeaderSection.Style.BorderColor.Default = Color.White;
groupHeaderSection.Style.BorderColor.Left = Color.Transparent;
//.........这里部分代码省略.........
示例4: Spell
public Element?[] Spell(string word, SearchAlgorithm algorithm)
{
Dictionary<int, Element> indexed = new Dictionary<int, Element>();
word = Regex.Replace(word.ToLower(), "[^a-z\\s]", "");
switch (algorithm)
{
case SearchAlgorithm.ElementBased:
foreach (Element element in elements)
{
string symbol = element.Symbol.ToLower();
if (word.Contains(symbol))
{
foreach (int i in word.IndexOfAll(symbol))
indexed.Add(i, element);
word = word.Replace(symbol, new string ('_', symbol.Length));
}
}
break;
case SearchAlgorithm.ChunkSearch:
int maxElementLength = elements.Max(e => e.Symbol.Length);
for (int searchLength = maxElementLength; searchLength > 0; searchLength--)
{
Element[] currentElements = elements.Where(e => e.Symbol.Length == searchLength).ToArray();
for (int x = 0; x < word.Length - searchLength + 1; x++)
foreach(Element currentElement in currentElements)
if (word.Substring(x, searchLength) == currentElement.Symbol.ToLower())
{
indexed.Add(x, currentElement);
ArrayList tmpList = new ArrayList(((ICollection)(Array)word.ToCharArray()));
tmpList.SetRange(x, (ICollection)(Array)new string('_', searchLength).ToCharArray());
word = new string(Array.ConvertAll(tmpList.ToArray(), item => (char)item));
}
}
break;
}
List<Element?> spelled = new List<Element?>();
int max = indexed.Max(item => item.Key);
Element value;
for (int i = 0; i <= max; i++)
{
if (indexed.TryGetValue(i, out value))
spelled.Add(value);
else if (word[i] == ' ')
spelled.Add(null);
}
return spelled.ToArray();
}