本文整理汇总了C#中IList.ToDictionary方法的典型用法代码示例。如果您正苦于以下问题:C# IList.ToDictionary方法的具体用法?C# IList.ToDictionary怎么用?C# IList.ToDictionary使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IList
的用法示例。
在下文中一共展示了IList.ToDictionary方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdateMarkers
public void UpdateMarkers(IList<MediaMarker> markers, bool forceRefresh)
{
var markersHash = markers.ToDictionary(i => i.Id, i => i);
List<MediaMarker> newMarkers;
List<MediaMarker> removedMarkers;
if (forceRefresh)
{
newMarkers = markers.ToList();
removedMarkers = _previousMarkers.Values.ToList();
}
else
{
newMarkers = markers.Where(i => !_previousMarkers.ContainsKey(i.Id)).ToList();
removedMarkers = _previousMarkers.Values.Where(i => !markersHash.ContainsKey(i.Id)).ToList();
}
if (removedMarkers.Any() && MarkersRemoved != null)
{
MarkersRemoved(removedMarkers);
}
if (newMarkers.Any() && NewMarkers != null)
{
NewMarkers(newMarkers);
}
_previousMarkers = markersHash;
}
示例2: ShowDatabases
public void ShowDatabases(IList<string> databases)
{
var dict = databases.ToDictionary(i => i, i => i);
_databaseComboBox.ValueMember = "Key";
_databaseComboBox.DisplayMember = "Value";
_databaseComboBox.DataSource = new BindingSource(dict, null);
}
示例3: TrendMarkerLabelProvider
public TrendMarkerLabelProvider(int polarityId)
{
switch (polarityId)
{
case PolarityIds.RagLowIsGood:
Labels = new List<TrendMarkerLabel> {
CannotBeCalculated,
new TrendMarkerLabel{Id = TrendMarker.Increasing, Text = "Increasing and getting worse"},
new TrendMarkerLabel{Id = TrendMarker.Decreasing, Text = "Decreasing and getting better"},
NoChange
};
break;
case PolarityIds.RagHighIsGood:
Labels = new List<TrendMarkerLabel> {
CannotBeCalculated,
new TrendMarkerLabel{Id = TrendMarker.Increasing, Text = "Increasing and getting better"},
new TrendMarkerLabel{Id = TrendMarker.Decreasing, Text = "Decreasing and getting worse"},
NoChange
};
break;
default:
Labels = new List<TrendMarkerLabel> {
CannotBeCalculated,
new TrendMarkerLabel{Id = TrendMarker.Increasing, Text = "Increasing"},
new TrendMarkerLabel{Id = TrendMarker.Decreasing, Text = "Decreasing"},
NoChange
};
break;
}
_trendMarkerToLabel = Labels.ToDictionary(x => x.Id, x => x);
}
示例4: ShowWriteOffOptions
public void ShowWriteOffOptions(IList<WriteOffOption> options)
{
var dict = options.ToDictionary(x => x.Id, x => x.Name);
_optionComboBox.DisplayMember = "Value";
_optionComboBox.ValueMember = "Key";
_optionComboBox.DataSource = new BindingSource(dict, null);
_optionComboBox.SelectedIndex = 0;
}
示例5: OperatorManager
public OperatorManager(IList<IOperator> operators)
{
Operators = new ReadOnlyDictionary<char, IOperator>(operators.ToDictionary(o => o.OperatorCharacter, o => o));
Priorities = operators.Select(o => o.Priority)
.Distinct()
.OrderBy(g => g)
.ToList()
.AsReadOnly();
}
示例6: GetEntityHierarchy
public EntityHierarchy GetEntityHierarchy(
Entity entity,
IList<PropertyDeleteOption> deleteOptions = null)
{
var deleteOptionsDict = deleteOptions == null ?
null :
deleteOptions.ToDictionary(x => x.HierarchyName);
return GetEntityHierarchy(null, entity, deleteOptionsDict);
}
示例7: ParseInput
static void ParseInput()
{
n = int.Parse(Console.ReadLine());
stationsInfo = Regex.Matches(
("0 --> " + Console.ReadLine()).Replace(" --> ", "►"),
"([^►]+)►([^►]+)"
).Cast<Match>()
.Select(match =>
new KeyValuePair<string, int>(
match.Groups[2].Value,
int.Parse(match.Groups[1].Value)
)
).ToArray();
int id = 0;
stationsByName = stationsInfo.ToDictionary(
info => info.Key,
info => id++
);
stationsByIndex = stationsByName.ToDictionary(
kvp => kvp.Value,
kvp => kvp.Key
);
var separator = new string[] { " | " };
camerasInfo = Enumerable.Range(0, int.Parse(Console.ReadLine()))
.Select(_ => Console.ReadLine())
.Select(line => line.Split(separator, StringSplitOptions.None))
.Select(match =>
new Tuple<DateTime, int, int, int, char>(
DateTime.ParseExact(match[0], DateFormat, CultureInfo.InvariantCulture),
stationsByName[match[1]],
int.Parse(match[2]),
int.Parse(match[3]),
match[4][0]
)
).ToArray();
trainCapacity = int.Parse(Console.ReadLine());
#if DEBUG
//Console.WriteLine("# INPUT");
//Console.WriteLine(string.Join(Environment.NewLine, stationsInfo));
//Console.WriteLine();
//Console.WriteLine(string.Join(Environment.NewLine, camerasInfo));
//Console.WriteLine();
//Console.WriteLine(trainCapacity);
//Console.WriteLine();
#endif
}
示例8: TreeClientApp
public TreeClientApp(IList<String> sampleFiles)
{
timer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(0.3) };
timer.Tick += TimerStepForward;
Program = String.Empty;
ExecuteProgramCommand = new RelayCommand(ExecuteProgram);
StepForwardCommand = new RelayCommand(StepForward, p => currentProgram != null);
PlayCommand = new RelayCommand(Play, p => currentProgram != null);
Samples = sampleFiles.ToDictionary(s => Path.GetFileName(s), s => new RelayCommand(o => LoadSample(s)));
}
示例9: GetEntityHierarchy
public EntityHierarchy GetEntityHierarchy(
Entity entity,
IList<PropertyDeleteOption> deleteOptions = null)
{
var deleteOptionsDict = deleteOptions == null ?
null :
deleteOptions.ToDictionary(x => x.HierarchyName);
var index = 0;
return GetEntityHierarchy(null, entity, deleteOptionsDict, string.Empty, ref index);
}
示例10: Behaviors
public ActionResult Behaviors(IList<BehaviorConfig> configs)
{
foreach (var config in configs)
{
BehaviorConfig.Update(CurrentInstance.Name, config);
}
var weights = configs.ToDictionary(c => c.BehaviorType, c => c.Weight);
RecommendationEngineConfiguration.ChangeBehaviorWeights(CurrentInstance.Name, weights);
return AjaxForm().ReloadPage();
}
示例11: BadShooterViewModel
public BadShooterViewModel(string name, double radius, IList<PlayerViewModel> players, ISoundEffect audioPlayer, IGunAimPhysics gunAimPhysics)
{
Name = name;
Radius = radius;
this.players = players;
this.audioPlayer = audioPlayer;
this.gunAimPhysics = gunAimPhysics;
scores = players.ToDictionary(p => p.Key, p => 0);
animationTimer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(10) };
animationTimer.Tick += DispatcherTimerOnTick;
gameTimer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(1) };
gameTimer.Tick += CountDown;
}
示例12: CategoryAreaDataWriter
public CategoryAreaDataWriter(IAreasReader areasReader, IGroupDataReader groupDataReader, WorksheetInfo worksheet,
ProfileDataWriter profileDataWriter, CategoryAreaType categoryAreaType)
: base(areasReader, groupDataReader, worksheet, profileDataWriter)
{
_categoryAreaTypeId = categoryAreaType.CategoryTypeId;
categories = areasReader.GetCategories(_categoryAreaTypeId);
subnationalCategoryIdToCategoryAreaMap = categories
.ToDictionary<Category, int, IArea>(
category => category.Id,
category => CategoryArea.New(category)
);
}
示例13: SelectStartingTeamForGameweek
public TeamSelection SelectStartingTeamForGameweek(IList<PredictedPlayerScore> predictedPlayerScores)
{
if(predictedPlayerScores.Count != 15)throw new Exception("Incorrect number of players to select starting team from");
var selection = new TeamSelection
{
Team = SelectTeam(predictedPlayerScores)
};
selection.PredictedTotalTeamScore = CalculatePredictedTeamScore(
predictedPlayerScores.ToDictionary(ps => ps.Player.Id, ps => ps.PredictedScore),
selection.Team);
return selection;
}
示例14: TaskList
public TaskList(IEnumerable<TaskTable> tasks, IEnumerable<CategoryTable> categories, int currentPosition = 0)
{
_tasks = tasks.ToList();
_taskDictionary = _tasks.ToDictionary(task => task.Id);
_category = categories.ToDictionary(cat => cat.Id);
_enumerator = new TaskEnumerator(this) { CurrentPosition = currentPosition };
}
示例15: Parse
/// <summary>
/// Parse stream output declarations.
/// Format is "[slot :] semantic[index][.mask] ; ...".
/// </summary>
/// <param name="entries">The parsed entries.</param>
/// <param name="strides">The output strides.</param>
/// <param name="streams">The output declarations to parse.</param>
public static void Parse(IList<ShaderStreamOutputDeclarationEntry> entries, out int[] strides, string[] streams, IList<Variable> fields)
{
strides = new int[4];
var fieldsBySemantic = fields.ToDictionary(x => Semantic.Parse(x.Qualifiers.OfType<Semantic>().Single().Name));
for (int streamIndex = 0; streamIndex < streams.Length; ++streamIndex)
{
// Parse multiple declarations separated by semicolon
var stream = streams[streamIndex];
foreach (var streamOutput in stream.Split(';'))
{
// Parse a single declaration: "[slot :] semantic[index][.mask]"
var match = streamOutputRegex.Match(streamOutput);
if (!match.Success)
throw new InvalidOperationException("Could not parse stream output.");
var streamOutputDecl = new ShaderStreamOutputDeclarationEntry();
// Split semantic into (name, index)
var semantic = Semantic.Parse(match.Groups[3].Value);
streamOutputDecl.SemanticName = semantic.Key;
streamOutputDecl.SemanticIndex = semantic.Value;
//if (streamOutputDecl.SemanticName == "$SKIP")
// streamOutputDecl.SemanticName = null;
var matchingField = fieldsBySemantic[semantic];
var matchingFieldType = matchingField.Type.TypeInference.TargetType ?? matchingField.Type;
if (matchingFieldType is VectorType)
streamOutputDecl.ComponentCount = (byte)((VectorType)matchingFieldType).Dimension;
else if (matchingFieldType is ScalarType)
streamOutputDecl.ComponentCount = 1;
else
throw new InvalidOperationException(string.Format("Could not recognize type of stream output for {0}.", matchingField));
var mask = match.Groups[5].Value;
ParseMask(mask, ref streamOutputDecl.StartComponent, ref streamOutputDecl.ComponentCount);
byte.TryParse(match.Groups[2].Value, out streamOutputDecl.OutputSlot);
streamOutputDecl.Stream = streamIndex;
strides[streamOutputDecl.OutputSlot] += streamOutputDecl.ComponentCount * sizeof(float);
entries.Add(streamOutputDecl);
}
}
}