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


C# Collection.IndexOf方法代码示例

本文整理汇总了C#中Collection.IndexOf方法的典型用法代码示例。如果您正苦于以下问题:C# Collection.IndexOf方法的具体用法?C# Collection.IndexOf怎么用?C# Collection.IndexOf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Collection的用法示例。


在下文中一共展示了Collection.IndexOf方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: PromptForChoice

        public override int PromptForChoice(string caption, string message, Collection<ChoiceDescription> choices,
                                            int defaultChoice)
        {
            if (Context.Job == null)
            {
                throw new NotImplementedException();
            }

            var parameters =
                new Hashtable(choices.ToDictionary(p => "btn_" + choices.IndexOf(p),
                                                   p => WebUtil.SafeEncode(p.Label.Replace("&", ""))))
                    {
                        {"te", message},
                        {"cp", caption},
                        {"dc", defaultChoice.ToString(CultureInfo.InvariantCulture)}
                    };
            Context.Site = Factory.GetSite(Context.Job.Options.SiteName);

            string dialogResult = JobContext.ShowModalDialog(parameters, "ConfirmChoice", "800", "300");
            if (!string.IsNullOrEmpty(dialogResult))
            {
                return int.Parse(dialogResult.Substring(4));
            }
            return -1;
        }
开发者ID:scjunkie,项目名称:Console,代码行数:25,代码来源:ScriptingHostUserInterface.cs

示例2: ConvertToTextExpressionImports

        internal static void ConvertToTextExpressionImports(VisualBasicSettings settings, out IList<string> importedNamespace, out IList<AssemblyReference> references)
        {
            importedNamespace = new Collection<string>();
            List<string> assemblyNames = new List<string>();
            foreach (VisualBasicImportReference visualbasicImport in settings.ImportReferences)
            {
                if (!BlackListedAssemblies.Contains(visualbasicImport.Assembly))
                {
                    if (importedNamespace.IndexOf(visualbasicImport.Import) == -1)
                    {
                        importedNamespace.Add(visualbasicImport.Import);
                    }

                    string displayName = visualbasicImport.Assembly.Split(',')[0];
                    if (assemblyNames.IndexOf(displayName) == -1)
                    {
                        assemblyNames.Add(displayName);
                    }
                }
            }

            references = new Collection<AssemblyReference>();
            foreach (string assemblyName in assemblyNames)
            {
                AssemblyReference reference = new AssemblyReference
                {
                    AssemblyName = new AssemblyName(assemblyName)
                };

                references.Add(reference);
            }
        }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:32,代码来源:NamespaceHelper.cs

示例3: PromptForChoice

        public override int PromptForChoice(string caption, string message, Collection<ChoiceDescription> choices,
            int defaultChoice)
        {
            if (Context.Job == null)
            {
                throw new NotImplementedException();
            }

            var parameters =
                new Hashtable(choices.ToDictionary(p => "btn_" + choices.IndexOf(p),
                    p => WebUtil.SafeEncode(p.Label.Replace("&", ""))))
                {
                    {"te", message},
                    {"cp", caption},
                    {"dc", defaultChoice.ToString(CultureInfo.InvariantCulture)}
                };
            Context.Site = Factory.GetSite(Context.Job.Options.SiteName);
            var lineWidth = choices.Count*80 + 140;
            var strLineWidth = lineWidth/8;
            var lineHeight = 0;
            foreach (var line in message.Split('\n'))
            {
                lineHeight += 1 + line.Length/strLineWidth;
            }
            lineHeight = Math.Max(lineHeight*21 + 130,150);
            var dialogResult = JobContext.ShowModalDialog(parameters, "ConfirmChoice",
                lineWidth.ToString(CultureInfo.InvariantCulture), lineHeight.ToString(CultureInfo.InvariantCulture));

            if (!string.IsNullOrEmpty(dialogResult))
            {
                return int.Parse(dialogResult.Substring(4));
            }
            return -1;
        }
开发者ID:ostat,项目名称:Console,代码行数:34,代码来源:ScriptingHostUserInterface.cs

示例4: PromptForChoice

 public override int PromptForChoice(string caption, string message, Collection<ChoiceDescription> choices, int defaultChoice)
 {
     Console.ForegroundColor = PSColors.outputText;
     Console.WriteLine(caption);
     Console.WriteLine(message);
     int choiceInt = defaultChoice;
     foreach (ChoiceDescription choice in choices)
     {
         Console.ForegroundColor = PSColors.outputText;
         if (choices.IndexOf(choice) == defaultChoice)
         {
             Console.ForegroundColor = PSColors.warningText;
         }
         Console.WriteLine("[{0}] {1} ", choices.IndexOf(choice), choice.Label.ToString().Replace("&",""));
     }
     Console.WriteLine("Default is: {0}", choices[defaultChoice].Label.ToString().Replace("&",""));
     Console.Write("\nEnter your choice: ");
     string choiceStr = Console.ReadLine();
     choiceInt = Int32.Parse(choiceStr);
     return choiceInt;
 }
开发者ID:CapTheFlag,项目名称:PSAttack,代码行数:21,代码来源:PSAttackHostUserInterface.cs

示例5: Run

        public static void Run()
        {
            Collection<string> dinosaurs = new Collection<string>();

            dinosaurs.Add("Psitticosaurus");
            dinosaurs.Add("Caudipteryx");
            dinosaurs.Add("Compsohnathus");
            dinosaurs.Add("Muttaburrasaurus");

            Console.WriteLine("{0} dinosaurs:", dinosaurs.Count);
            Display(dinosaurs);

            Console.WriteLine("\nIndexOf(\"Muttaburrasaurus\"): {0}", dinosaurs.IndexOf("Muttaburrasaurus"));

            Console.WriteLine("\nContains(\"Caudipteryx\"): {0}",  dinosaurs.Contains("Caudipteryx"));

            Console.WriteLine("\nInsert(2, \"Nanotyrannus\")");
            dinosaurs.Insert(2, "Nanotyrannus");
            Display(dinosaurs);

            Console.WriteLine("\ndinosaurs[2]: {0}", dinosaurs[2]);

            Console.WriteLine("\ndinosaurs[2] = \"Microraptor\"");
            dinosaurs[2] = "Microraptor";
            Display(dinosaurs);

            Console.WriteLine("\nRemove(\"Microraptor\")");
            dinosaurs.Remove("Microraptor");
            Display(dinosaurs);

            Console.WriteLine("\nRemoveAt(0)");
            dinosaurs.RemoveAt(0);
            Display(dinosaurs);

            Console.WriteLine("\ndinosaurs.Clear()");
            dinosaurs.Clear();
            Console.WriteLine("Count: {0}", dinosaurs.Count);
        }
开发者ID:oblivious,项目名称:Oblivious,代码行数:38,代码来源:CollectionGeneric.cs

示例6: GetInstructionText

        public static string GetInstructionText(Collection<Instruction> ic, int insIndex, bool deepCheck)
        {
            if (insIndex == -1) return "?";

            // check dead loop
            string opText;
            if (ic[insIndex].Operand is Instruction)
            {
                if (deepCheck)
                {
                    Instruction op = (Instruction)ic[insIndex].Operand;
                    opText = GetInstructionText(ic, ic.IndexOf(op), false);
                }
                else
                {
                    opText = insIndex.ToString();
                }
            }
            else
            {
                opText = InsUtils.GetOperandText(ic, insIndex);
            }
            return String.Format("{0} -> {1} {2}", insIndex, ic[insIndex].OpCode.Name, opText);
        }
开发者ID:adisik,项目名称:simple-assembly-explorer,代码行数:24,代码来源:InsUtils.cs

示例7: RemoveArgumentWeavingCall

        private Tuple<TypeDefinition, int> RemoveArgumentWeavingCall(MethodDefinition method, Collection<Instruction> instructions, Instruction instruction)
        {
            TypeReference displayClassType = null;
            var index = instructions.IndexOf(instruction);

            for (var i = index; i >= 0; i--)
            {
                // Remove everything until the first ldloc.0 call
                var innerInstruction = instructions[i];

                instructions.RemoveAt(i);

                if (innerInstruction.IsOpCode(OpCodes.Ldtoken))
                {
                    if (displayClassType == null)
                    {
                        // First call to ldtoken with FieldDefinition contains the display class type
                        var fieldDefinition = GetFieldDefinition(innerInstruction);
                        if (fieldDefinition != null)
                        {
                            displayClassType = fieldDefinition.DeclaringType;
                        }
                    }
                }

                // Regular code
                if (innerInstruction.IsOpCode(OpCodes.Ldloc_0, OpCodes.Ldloc))
                {
                    break;
                }

                // Async/await code
                if (innerInstruction.IsOpCode(OpCodes.Ldarg, OpCodes.Ldarg_0))
                {
                    break;
                }

                // Since .NET core, we want to skip assignments:
                //
                //   ldarg.0 
                //   stfld class MyClass/<>c__DisplayClass0_0`1<!!T>::myArgument
                // 
                // If the display class is no longer used, another method must remove the code
                if (innerInstruction.IsOpCode(OpCodes.Stfld, OpCodes.Ldarg, OpCodes.Ldarg_0, OpCodes.Ldarg_1, OpCodes.Ldarg_2, OpCodes.Ldarg_3))
                {
                    break;
                }

                // .net core code
                if (innerInstruction.IsOpCode(OpCodes.Dup))
                {
                    break;
                }

                index = i;
            }

            return new Tuple<TypeDefinition, int>(displayClassType.Resolve(), index - 1);
        }
开发者ID:Catel,项目名称:Catel.Fody,代码行数:59,代码来源:ArgumentWeaver.expressions.cs

示例8: addStationInSequence

        private void addStationInSequence(Collection<TVStation> sortedStations, TVStation newStation)
        {
            foreach (TVStation currentStation in sortedStations)
            {
                int sequence = currentStation.Name.CompareTo(newStation.Name);

                if (sequence > 0)
                {
                    sortedStations.Insert(sortedStations.IndexOf(currentStation), newStation);
                    return;
                }
                else
                {
                    if (sequence == 0)
                    {
                        if (currentStation.EPGCollection.Count == 0)
                        {
                            sortedStations.Insert(sortedStations.IndexOf(currentStation), newStation);
                            return;
                        }
                    }
                }
            }

            sortedStations.Add(newStation);
        }
开发者ID:esurharun,项目名称:TSDumper,代码行数:26,代码来源:EPGController.cs

示例9: IsSimple

        /// <summary>
        ///  Returns 'true' if this Geometry has no anomalous geometric points, such as self
        /// intersection or self tangency. The description of each instantiable geometric class will include the specific
        /// conditions that cause an instance of that class to be classified as not simple.
        /// </summary>
        /// <returns>true if the geometry is simple</returns>
        public override bool IsSimple()
        {
            //Collection<Point> verts = new Collection<Point>(_Vertices.Count);
            Collection<Point> verts = new Collection<Point>();

            for (int i = 0; i < _Vertices.Count; i++)
                //if (!verts.Exists(delegate(SharpMap.Geometries.Point p) { return p.Equals(_Vertices[i]); }))
                if (0 != verts.IndexOf(_Vertices[i]))
                    verts.Add(_Vertices[i]);

            return (verts.Count == _Vertices.Count - (IsClosed ? 1 : 0));
        }
开发者ID:TNOCS,项目名称:csTouch,代码行数:18,代码来源:LineString.cs

示例10: IsSimple

        /// <summary>
        ///  Returns 'true' if this Geometry has no anomalous geometric points, such as self
        /// intersection or self tangency. The description of each instantiable geometric class will include the specific
        /// conditions that cause an instance of that class to be classified as not simple.
        /// </summary>
        /// <returns>true if the geometry is simple</returns>
        public bool IsSimple()
        {
            var verts = new Collection<Point>();

            foreach (Point vertex in _vertices)
                if (0 != verts.IndexOf(vertex))
                    verts.Add(vertex);

            return (verts.Count == _vertices.Count - (IsClosed ? 1 : 0));
        }
开发者ID:jdeksup,项目名称:Mapsui.Net4,代码行数:16,代码来源:LineString.cs

示例11: FindPreviousWord

        /// <summary>
        /// Find previos word, which is normal word
        /// Change it to public for code re-use in script sentence.
        /// </summary>
        /// <param name="words">Word collection to search.</param>
        /// <param name="word">Word to find previous word for.</param>
        /// <returns>Found word.</returns>
        public static ScriptWord FindPreviousWord(Collection<ScriptWord> words, ScriptWord word)
        {
            if (words == null)
            {
                throw new ArgumentNullException("words");
            }

            if (word == null)
            {
                throw new ArgumentNullException("word");
            }

            int index = words.IndexOf(word);
            if (index == -1)
            {
                throw new ArgumentOutOfRangeException("word");
            }

            while (index - 1 >= 0)
            {
                if (words[index - 1].WordType == WordType.Normal)
                {
                    return words[index - 1];
                }

                --index;
            }

            return null;
        }
开发者ID:JohnsonYuan,项目名称:TTSFramework,代码行数:37,代码来源:ScriptItem.cs

示例12: GetIndexedPixels

		/// <summary>
		/// Gets the indices of the colours of each of the supplied pixels 
		/// within the colour table.
		/// </summary>
		/// <param name="pixelColours">
		/// A collection of the colours for which to get the indices in the 
		/// colour table.
		/// </param>
		/// <returns>
		/// A collection of the indices of the colours of each of the supplied 
		/// pixels within the colour table.
		/// </returns>
		private IndexedPixels GetIndexedPixels( Color[] pixelColours )
		{
			IndexedPixels indexedPixels = new IndexedPixels();
			// Take a copy of the distinct colours to make the IndexOf method
			// available
			string copyDistinctColoursCounterText = "Copying distinct colours";
			AddCounter( copyDistinctColoursCounterText, _distinctColours.Count );
			Collection<Color> distinctColours = new Collection<Color>();
			foreach( Color c in _distinctColours.Keys )
			{
				MyProgressCounters[copyDistinctColoursCounterText].Value++;
				distinctColours.Add( c );
			}
			RemoveCounter( copyDistinctColoursCounterText );

			int indexInColourTable;
			int red;
			int green;
			int blue;
			int numberOfPixels = pixelColours.Length;
			string indexingPixelsCounterText 
				= "Mapping colours to indices in colour table";
			AddCounter( indexingPixelsCounterText, numberOfPixels );
			
			for( int i = 0; i < numberOfPixels; i++ )
			{
				MyProgressCounters[indexingPixelsCounterText].Value = i;
				red = pixelColours[i].R;
				green = pixelColours[i].G;
				blue = pixelColours[i].B;
				
				// Get the index in the colour table of the colour of this pixel
				if( _distinctColours.Count > 256 )
				{
					indexInColourTable = _nq.Map( red, green, blue );
				}
				else
				{
					indexInColourTable = distinctColours.IndexOf( pixelColours[i] );
				}
				indexedPixels.Add( (byte) indexInColourTable );
			}
			RemoveCounter( indexingPixelsCounterText );
			return indexedPixels;
		}
开发者ID:hanistory,项目名称:hasuite,代码行数:57,代码来源:PixelAnalysis.cs

示例13: addPid

        private void addPid(Collection<PidSpec> pidList, PidSpec newPID)
        {
            foreach (PidSpec oldPID in pidList)
            {
                if (oldPID.Pid == newPID.Pid)
                    return;

                if (oldPID.Pid > newPID.Pid)
                {
                    pidList.Insert(pidList.IndexOf(oldPID), newPID);
                    return;
                }
            }

            pidList.Add(newPID);
        }
开发者ID:esurharun,项目名称:TSDumper,代码行数:16,代码来源:TransportStreamAnalyzeControl.cs

示例14: addCountry

        /// <summary>
        /// Add a country to a collection.
        /// </summary>
        /// <param name="newCountry">The country to be added.</param>
        /// <param name="countries">The collection of countries to be added to.</param>
        public static void addCountry(Country newCountry, Collection<Country> countries)
        {
            if (countries.Count == 0)
            {
                Country undefinedCountry = new Country("-- Undefined --", "");
                Area undefinedArea = new Area("-- Undefined --", 0);
                undefinedArea.Regions.Add(new Region("-- Undefined --", 0));
                undefinedCountry.Areas.Add(undefinedArea);
                countries.Add(undefinedCountry);
            }

            foreach (Country oldCountry in countries)
            {
                if (oldCountry.Code == newCountry.Code)
                    return;

                if (oldCountry.Code.CompareTo(newCountry.Code) > 0)
                {
                    countries.Insert(countries.IndexOf(oldCountry), newCountry);
                    return;
                }
            }

            countries.Add(newCountry);
        }
开发者ID:esurharun,项目名称:TSDumper,代码行数:30,代码来源:Country.cs

示例15: Parse

        /// <summary>
        /// Parse words to intonation phrase.
        /// </summary>
        /// <param name="intonationWords">Words to be parsed.</param>
        public void Parse(Collection<ScriptWord> intonationWords)
        {
            IntermediatePhrases.Clear();
            Collection<ScriptWord> words = new Collection<ScriptWord>();
            for (int i = 0; i < intonationWords.Count; i++)
            {
                ScriptWord word = intonationWords[i];
                words.Add(word);
                if (word.IsPronouncableNormalWord &&
                    (word.Break >= TtsBreak.InterPhrase ||
                    intonationWords.IndexOf(word) == (intonationWords.Count - 1)))
                {
                    // Append non-normal word to the intonation break phrase.
                    for (int j = i + 1; j < intonationWords.Count; j++)
                    {
                        if (intonationWords[j].IsPronouncableNormalWord)
                        {
                            break;
                        }
                        else
                        {
                            words.Add(intonationWords[j]);
                            i = j;
                        }
                    }

                    ScriptIntermediatePhrase phrase = new ScriptIntermediatePhrase()
                    {
                        IntonationPhrase = this,
                    };

                    phrase.Parse(words);
                    IntermediatePhrases.Add(phrase);
                    words.Clear();
                }
            }

            if (words.Count > 0)
            {
                ScriptIntermediatePhrase phrase = new ScriptIntermediatePhrase()
                {
                    IntonationPhrase = this,
                };

                phrase.Parse(words);
                IntermediatePhrases.Add(phrase);
                words.Clear();
            }
        }
开发者ID:JohnsonYuan,项目名称:TTSFramework,代码行数:53,代码来源:ScriptIntonationPhrase.cs


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