当前位置: 首页>>代码示例>>C#>>正文


C# System.Collections.Generic.Dictionary.TryGetValue方法代码示例

本文整理汇总了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);
		}
开发者ID:Xtremrules,项目名称:dot42,代码行数:10,代码来源:Case656.cs

示例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");
        }
开发者ID:Xtremrules,项目名称:dot42,代码行数:10,代码来源:Case657.cs

示例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");
		}
开发者ID:Xtremrules,项目名称:dot42,代码行数:10,代码来源:Case656.cs

示例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;
                        }
                    }
                    );
                }
            }
        }
开发者ID:dguder,项目名称:nant,代码行数:87,代码来源:Project.cs


注:本文中的System.Collections.Generic.Dictionary.TryGetValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。