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


C# Collection.Insert方法代码示例

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


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

示例1: MakeLastStatementReturn

    public void MakeLastStatementReturn()
    {

        instructions = Method.Body.Instructions;
        FixHangingHandlerEnd();

        sealBranchesNop = Instruction.Create(OpCodes.Nop);
        instructions.Add(sealBranchesNop);

        NopBeforeReturn = Instruction.Create(OpCodes.Nop);

        if (IsMethodReturnValue())
        {
            returnVariable = new VariableDefinition(Method.MethodReturnType.ReturnType);
            Method.Body.Variables.Add(returnVariable);
        }

        for (var index = 0; index < instructions.Count; index++)
        {
            var operand = instructions[index].Operand as Instruction;
            if (operand != null)
            {
                if (operand.OpCode == OpCodes.Ret)
                {
                    if (IsMethodReturnValue())
                    {
                        // The C# compiler never jumps directly to a ret
                        // when returning a value from the method. But other Fody
                        // modules and other compilers might. So store the value here.
                        instructions.Insert(index, Instruction.Create(OpCodes.Stloc, returnVariable));
                        instructions.Insert(index, Instruction.Create(OpCodes.Dup));
                        index += 2;
                    }

                    instructions[index].Operand = sealBranchesNop;
                }
            }
        }

        if (!IsMethodReturnValue())
        {
            WithNoReturn();
            return;
        }
        WithReturnValue();
    }
开发者ID:AndreGleichner,项目名称:Anotar,代码行数:46,代码来源:ReturnFixer.cs

示例2: When_Adding_a_new_item_with_index_0_Should_Add_the_item_at_the_beginning_of_the_collection

        public void When_Adding_a_new_item_with_index_0_Should_Add_the_item_at_the_beginning_of_the_collection()
        {
            var col = new Collection<string>();

            col.Add("1");
            col.Add("2");
            col.Add("3");

            col.Insert(0, "4");

            Assert.That(col[0], Is.EqualTo("4"));
        }
开发者ID:hgarcia,项目名称:Pronghorn,代码行数:12,代码来源:RouteCollectionExtensionTests.cs

示例3: 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

示例4: Run

        /// <summary>
        /// Runs this executable and places the output in the specified output file. The inputs are written to a temporary file that is deleted when finished.
        /// This executable is run with the following string <c>[this.ExecutablePath] --register-ext [ExtensionMapping] --output=[outputfile] --files-from=[input file] [addititionlArguments]</c>
        /// </summary>
        /// <param name="outputFile">The output file.</param>
        /// <param name="additionalArguments">The additional arguments.</param>
        /// <param name="inputs">The inputs.</param>
        public void Run(string outputFile, Collection<string> additionalArguments, Collection<string> inputs)
        {
            if (null == inputs)
                throw new ArgumentNullException("inputs");

            var arguments = new Collection<string>(additionalArguments);

            var tempFileListing = Path.GetTempFileName();
            using (StreamWriter writer = new StreamWriter(tempFileListing))
            {
                foreach (var input in inputs)
                {
                    writer.WriteLine(input);
                }
            }
            arguments.Insert(0, String.Format(CultureInfo.InvariantCulture, "--files-from=\"{0}\"", tempFileListing));

            try
            {
                this.Run(outputFile, arguments);
            }
            catch (SrcMLException)
            {
                throw;
            }
            finally
            {
                File.Delete(tempFileListing);
            }
        }
开发者ID:vinayaugustine,项目名称:SrcML.NET,代码行数:37,代码来源:SrcMLRunner.cs

示例5: AddReturnNullGuard

    private void AddReturnNullGuard(Collection<Instruction> instructions, int ret, TypeReference returnType, string errorMessage, params Instruction[] finalInstructions)
    {
        var returnInstruction = instructions[ret];

        var guardInstructions = new List<Instruction>();

        if (isDebug)
        {
            InstructionPatterns.DuplicateReturnValue(guardInstructions, returnType);

            InstructionPatterns.CallDebugAssertInstructions(guardInstructions, errorMessage);
        }

        InstructionPatterns.DuplicateReturnValue(guardInstructions, returnType);

        InstructionPatterns.IfNull(guardInstructions, returnInstruction, i =>
        {
            // Clean up the stack since we're about to throw up.
            i.Add(Instruction.Create(OpCodes.Pop));

            InstructionPatterns.LoadInvalidOperationException(i, errorMessage);

            i.AddRange(finalInstructions);
        });

        instructions.Insert(ret, guardInstructions);
    }
开发者ID:JakeGinnivan,项目名称:NullGuard,代码行数:27,代码来源:MethodProcessor.cs

示例6: ProcessArgs


//.........这里部分代码省略.........
                    }

                    ShutdownApp();
                }

                if (string.Compare(args[0], "Auto", true) == 0)
                {
                    if (
                        File.Exists(
                            Path.Combine(Environment.ExpandEnvironmentVariables("%WINDIR%"), "Temp", "abort.lock")))
                    {
                        try
                        {
                            File.Delete(
                                Path.Combine(Environment.ExpandEnvironmentVariables("%WINDIR%"), "Temp", "abort.lock"));
                        }
                        catch (Exception e)
                        {
                            if (
                                !(e is OperationCanceledException || e is UnauthorizedAccessException
                                  || e is InvalidOperationException || e is NotSupportedException))
                            {
                                ErrorOccurred(
                                    null,
                                    new ErrorOccurredEventArgs(Utilities.GetExceptionAsString(e), ErrorType.FatalError));
                                throw;
                            }

                            Utilities.ReportError(e, ErrorType.GeneralError);
                        }
                    }

                    isAutoInstall = true;
                    IsInstalling = true;
                    notifyIcon.BalloonTipClicked += RunSevenUpdate;
                    notifyIcon.Click += RunSevenUpdate;
                    notifyIcon.Visible = true;
                    Search.ErrorOccurred += ErrorOccurred;

                    var apps = new Collection<Sua>();
                    if (File.Exists(ApplicationsFile))
                    {
                        apps = Utilities.Deserialize<Collection<Sua>>(ApplicationsFile);
                    }

                    var publisher = new ObservableCollection<LocaleString>();
                    var ls = new LocaleString { Value = "Seven Software", Lang = "en" };
                    publisher.Add(ls);

                    var name = new ObservableCollection<LocaleString>();
                    ls = new LocaleString { Value = "Seven Update", Lang = "en" };
                    name.Add(ls);

                    var app = new Sua(name, publisher)
                        {
                            AppUrl = @"http://sevenupdate.com/",
                            Directory = @"HKLM\Software\Microsoft\Windows\CurrentVersion\App Paths\SevenUpdate.exe",
                            ValueName = "Path",
                            HelpUrl = @"http://sevenupdate.com/support/",
                            Platform = Platform.AnyCpu,
                            IsEnabled = true,
                            SuiUrl = @"http://apps.sevenupdate.com/SevenUpdate"
                        };

                    string channel = null;
                    try
                    {
                        channel =
                            Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Seven Update", "channel", null).ToString();
                    }
                    catch (NullReferenceException)
                    {
                    }
                    catch (AccessViolationException)
                    {
                    }

                    switch (channel)
                    {
                        case "dev":
                            app.SuiUrl += @"-dev.sui";
                            break;
                        case "beta":
                            app.SuiUrl += @"-beta.sui";
                            break;
                        default:
                            app.SuiUrl += @".sui";
                            break;
                    }

                    apps.Insert(0, app);

                    Search.SearchForUpdates(apps, Path.Combine(AllUserStore, "downloads"));
                }
                else
                {
                    ShutdownApp();
                }
            }
        }
开发者ID:robertbaker,项目名称:SevenUpdate,代码行数:101,代码来源:App.cs

示例7: 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

示例8: TestAdd

        public void TestAdd()
        {
            var rand = new Random(3);

            ListCollection<string> list1 = new ListCollection<string>();
            Collection<string> list2 = new Collection<string>();

            //Check Add
            for (int x = 0; x < 100; x++)
            {
                var str = x.ToString();
                list1.Add(str);
                list2.Add(str);

                CheckEquals1(list1, list2);
            }

            //Check Remove
            for (int x = 100; x < 200; x++)
            {
                var str = x.ToString();
                var removeItem = list1[rand.Next(list1.Count)];
                list1.Remove(removeItem);
                list2.Remove(removeItem);

                CheckEquals1(list1, list2);

                list1.Add(str);
                list2.Add(str);

                CheckEquals1(list1, list2);
            }

            //Check RemoveAt
            for (int x = 0; x < 100; x++)
            {
                int index = rand.Next(list1.Count);
                list1.RemoveAt(index);
                list2.RemoveAt(index);

                CheckEquals1(list1, list2);
            }

            //Check Insert
            for (int x = 0; x < 100; x++)
            {
                int index = rand.Next(list1.Count);
                list1.Insert(index, x.ToString());
                list2.Insert(index, x.ToString());

                CheckEquals1(list1, list2);
            }

            //Check set
            for (int x = 0; x < 100; x++)
            {
                int index = rand.Next(list1.Count);
                list1[index] = x.ToString();
                list2[index] = x.ToString();

                CheckEquals1(list1, list2);
            }

            list1.Clear();
            list2.Clear();
            CheckEquals1(list1, list2);

            //Check Add
            for (int x = 0; x < 100; x++)
            {
                var str = x.ToString();
                list1.Add(str);
                list2.Add(str);

                CheckEquals1(list1, list2);
            }

            //Check indexOf
            for (int x = 0; x < 100; x++)
            {
                int index = rand.Next(list1.Count * 2);

                if (list1.IndexOf(index.ToString()) != list2.IndexOf(index.ToString()))
                    throw new Exception();

                CheckEquals1(list1, list2);
            }

            string[] lst1 = new string[list1.Count];
            string[] lst2 = new string[list2.Count];

            list1.CopyTo(lst1, 0);
            list2.CopyTo(lst2, 0);

            CheckEquals3(list1, list2);

            for (int x = 0; x < 100; x++)
            {
                int index = rand.Next(list1.Count * 2);

//.........这里部分代码省略.........
开发者ID:GridProtectionAlliance,项目名称:gsf,代码行数:101,代码来源:ListCollectionTests.cs

示例9: GetPreviousVersion

        /// <summary>
        /// Get the latest version that is less than the current version. 
        /// </summary>
        /// <param name="versions">The versions of specified file.</param>
        /// <returns>A string indicates a version that only less than current version.</returns>
        public static string GetPreviousVersion(VersionData[] versions)
        {
            #region Sort of descending order of version number
            // The version numbers collection that sort of descending order.
            Collection<string> versionsSortCollection = new Collection<string>();

            // Sort of descending order of version number
            foreach (VersionData versionData in versions)
            {
                // A Boolean value indicates whether this version number is smallest in the versionsSortCollection.
                bool isSmallest = true;
                for (int i = 0; i < versionsSortCollection.Count; i++)
                {
                    if (CompareVersionNumber(versionsSortCollection[i], versionData.version) == 1)
                    {
                        // If find a version in versionsSortCollection that less than this version,
                        // and then insert this version prior to the version that less than this version in the collection.
                        versionsSortCollection.Insert(i, versionData.version);
                        isSmallest = false;
                        break;
                    }
                }

                // If this version is the smallest one in the versionsSortCollection, add it to the end of 
                // the versionsSortCollection.
                if (isSmallest == true)
                {
                    versionsSortCollection.Add(versionData.version);
                }
            }
            #endregion

            // According to MS-OFCGLOS,the current version is the latest version of a document.
            // Then current version is the most recent version of the file.
            // So the first item in versionsSortCollection is current version and the second item is the version 
            // that less than current version.
            return versionsSortCollection[1];
        }
开发者ID:OfficeDev,项目名称:Interop-TestSuites,代码行数:43,代码来源:AdapterHelper.cs

示例10: addByUserChannel

        private void addByUserChannel(Collection<OpenTVChannel> sortedChannels, OpenTVChannel newChannel)
        {
            foreach (OpenTVChannel oldChannel in sortedChannels)
            {
                if (newChannel.UserChannel < oldChannel.UserChannel)
                {
                    sortedChannels.Insert(sortedChannels.IndexOf(oldChannel), newChannel);
                    return;
                }
            }

            sortedChannels.Add(newChannel);
        }
开发者ID:esurharun,项目名称:TSDumper,代码行数:13,代码来源:OpenTVController.cs

示例11: addByFlags

        private void addByFlags(Collection<OpenTVChannel> sortedChannels, OpenTVChannel newChannel)
        {
            foreach (OpenTVChannel oldChannel in sortedChannels)
            {
                if (compareFlags(newChannel.Flags, oldChannel.Flags) < 0)
                {
                    sortedChannels.Insert(sortedChannels.IndexOf(oldChannel), newChannel);
                    return;
                }
            }

            sortedChannels.Add(newChannel);
        }
开发者ID:esurharun,项目名称:TSDumper,代码行数:13,代码来源:OpenTVController.cs

示例12: doTimes

 private void doTimes(String results)
 {
     var movieTimes = new Collection<String>();
     var timesResult = JsonUtils.GetItems(results, new String[] { "day", "screenings" });
     foreach (Dictionary<String, String> times in timesResult)
     {
         if (times["day"] != "")
         {
             movieTimes.Add(times["day"] + "\n" + times["screenings"]);
         }
         else if (times["screenings"] != "")
         {
             int last = movieTimes.Count - 1;
             var previousTime = movieTimes.ElementAt(last);
             previousTime += " " + times["screenings"];
             movieTimes.RemoveAt(last);
             movieTimes.Insert(last, previousTime);
         }
         else
         {
             movieTimes.Add("No Showings!");
         }
     }
     Dispatcher.BeginInvoke(() => ShowingsList.ItemsSource = movieTimes);
 }
开发者ID:fluffy88,项目名称:Irish-Cinema-Listings,代码行数:25,代码来源:MoviePage.xaml.cs

示例13: SortPronunciationsForDomain

        /// <summary>
        /// Sort pronunciations for domain.
        /// </summary>
        /// <param name="domainTag">Domain tag.</param>
        private void SortPronunciationsForDomain(string domainTag)
        {
            Collection<LexiconPronunciation> sortedProns = new Collection<LexiconPronunciation>();
            foreach (LexiconPronunciation pron in _pronunciations)
            {
                if (pron.IsFirstDomainPronunciation(domainTag))
                {
                    sortedProns.Insert(0, pron);
                }
                else
                {
                    sortedProns.Add(pron);
                }
            }

            _pronunciations = sortedProns;
        }
开发者ID:JohnsonYuan,项目名称:TTSFramework,代码行数:21,代码来源:LexicalItem.cs

示例14: 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

示例15: 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


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