本文整理汇总了C#中System.Collections.Generic.Dictionary.TryGetValue方法的典型用法代码示例。如果您正苦于以下问题:C# System.Collections.Generic.Dictionary.TryGetValue方法的具体用法?C# System.Collections.Generic.Dictionary.TryGetValue怎么用?C# System.Collections.Generic.Dictionary.TryGetValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Generic.Dictionary
的用法示例。
在下文中一共展示了System.Collections.Generic.Dictionary.TryGetValue方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: test656_int
// Local output parameter s must not be initialized
public void test656_int()
{
var dict2 = new System.Collections.Generic.Dictionary<int, int>();
dict2.Add(1, 100);
dict2.Add(2, 200);
int s;
dict2.TryGetValue(2, out s);
AssertEquals(s, 200);
}
示例2: test657
// Local output parameter s must not be initialized
public void test657()
{
var dict2 = new System.Collections.Generic.Dictionary<NUMBER, string>();
dict2.Add(NUMBER.ONE, "One");
dict2.Add(NUMBER.TWO, "Two");
string s = "-";
dict2.TryGetValue(NUMBER.TWO, out s);
AssertEquals(s, "Two");
}
示例3: test656
// Local output parameter s must not be initialized
public void test656()
{
var dict2 = new System.Collections.Generic.Dictionary<int, string>();
dict2.Add(1, "One");
dict2.Add(2, "Two");
string s; // = "-";
dict2.TryGetValue(2, out s);
AssertEquals(s, "Two");
}
示例4: Execute
/// <summary>
/// Executes a specific target.
/// </summary>
/// <param name="targetName">The name of the target to execute.</param>
/// <param name="forceDependencies">Whether dependencies should be forced to execute</param>
/// <remarks>
/// Global tasks are not executed.
/// </remarks>
public void Execute(string targetName, bool forceDependencies)
{
bool singleThreaded = !RunTargetsInParallel;
if (singleThreaded) {
// sort the dependency tree, and run everything from the
// beginning until we hit our targetName.
//
// sorting checks if all the targets (and dependencies)
// exist, and if there is any cycle in the dependency
// graph.
TargetCollection sortedTargets = TopologicalTargetSort(targetName, Targets);
int currentIndex = 0;
Target currentTarget;
// store calling target
Target callingTarget = _currentTarget;
do {
// determine target that should be executed
currentTarget = (Target) sortedTargets[currentIndex++];
// store target that will be executed
_currentTarget = currentTarget;
// only execute targets that have not been executed already, if
// we are not forcing.
if (forceDependencies || !currentTarget.Executed || currentTarget.Name == targetName) {
currentTarget.Execute();
}
} while (currentTarget.Name != targetName);
// restore calling target, as a <call> task might have caused the
// current target to be executed and when finished executing this
// target, the target that contained the <call> task should be
// considered the current target again
_currentTarget = callingTarget;
}
else {
// sorting checks if all the targets (and dependencies)
// exist, and if there is any cycle in the dependency
// graph.
TopologicalTargetSort (targetName, Targets);
// Dictionary is faster than implementation in TargetCollection.Find
System.Collections.Generic.Dictionary<string, Target> targets = new System.Collections.Generic.Dictionary<string, Target>();
foreach (Target target in Targets) {
targets [target.Name] = target;
}
// Use execution graph to run targets in parallel
using (ExecutionGraph graph = new ExecutionGraph()) {
PopulateExecutionGraph(targetName, Targets, graph);
graph.WalkThrough(delegate(string currentTargetName) {
Target currentTarget;
if (!targets.TryGetValue(currentTargetName, out currentTarget)) {
Target wildcardTarget = targets [WildTarget];
currentTarget = wildcardTarget.Clone ();
currentTarget.Name = targetName;
}
Target savedTarget = _currentTarget;
_currentTarget = currentTarget;
try {
lock (currentTarget) {
if (forceDependencies || !currentTarget.Executed || currentTarget.Name == targetName) {
currentTarget.Execute ();
}
}
} finally {
_currentTarget = savedTarget;
}
}
);
}
}
}