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


C# List.InsertRange方法代码示例

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


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

示例1: VisitClassDeclaration

        protected override SyntaxNode VisitClassDeclaration(ClassDeclarationSyntax node)
        {
            var newTypeDeclaration = (TypeDeclarationSyntax)base.VisitClassDeclaration(node);

            if (_fields.Count > 0 || _methods.Count > 0)
            {
                var members = new List<MemberDeclarationSyntax>(newTypeDeclaration.Members);
                members.InsertRange(0, _methods);
                members.InsertRange(0, _fields);

                return ((ClassDeclarationSyntax)newTypeDeclaration).Update(
                    newTypeDeclaration.Attributes,
                    newTypeDeclaration.Modifiers,
                    newTypeDeclaration.Keyword,
                    newTypeDeclaration.Identifier,
                    newTypeDeclaration.TypeParameterListOpt,
                    newTypeDeclaration.BaseListOpt,
                    newTypeDeclaration.ConstraintClauses,
                    newTypeDeclaration.OpenBraceToken,
                    Syntax.List(members.AsEnumerable()),
                    newTypeDeclaration.CloseBraceToken,
                    newTypeDeclaration.SemicolonTokenOpt);
            }

            return newTypeDeclaration;
        }
开发者ID:melkio,项目名称:uan12,代码行数:26,代码来源:DependencyPropertyRewriter.cs

示例2: GetAllArt

 public List<string> GetAllArt()
 {
     List<string> paths = new List<string>();
     paths.InsertRange(0, GetPlaylistArt());
     paths.InsertRange(paths.Count - 1, GetAlbumArt());
     return paths;
 } 
开发者ID:tschafma,项目名称:Jukebox,代码行数:7,代码来源:ArtRepository.cs

示例3: GetBytes

        /// <summary>
        /// Gets the bytes matching the expected Kafka structure. 
        /// </summary>
        /// <returns>The byte array of the request.</returns>
        public override byte[] GetBytes()
        {
            List<byte> encodedMessageSet = new List<byte>();
            encodedMessageSet.AddRange(GetInternalBytes());

            byte[] requestBytes = BitWorks.GetBytesReversed(Convert.ToInt16((int)RequestType.Produce));
            encodedMessageSet.InsertRange(0, requestBytes);
            encodedMessageSet.InsertRange(0, BitWorks.GetBytesReversed(encodedMessageSet.Count));

            return encodedMessageSet.ToArray();
        }
开发者ID:precog,项目名称:kafka,代码行数:15,代码来源:ProducerRequest.cs

示例4: GetMatchingArtifactsFrom

        /// <summary>
        /// Returns Artifacts files'information list from a given folder respecting include and exclude pattern
        /// </summary>
        /// <param name="directoryPath"></param>
        /// <param name="includePatterns"></param>
        /// <param name="excludePatterns"></param>
        public static IList<FileInfo> GetMatchingArtifactsFrom(string directoryPath, string includePatterns, string excludePatterns)
        {
            var fileInfos = new List<FileInfo>();

            if (Directory.Exists((directoryPath)))
            {
                var includeFiles = new List<string>();
                if (!string.IsNullOrEmpty(includePatterns))
                {
                    foreach (var includePattern in includePatterns.Split(','))
                    {

                        if (includePattern.Contains(@"\") || includePattern.Contains(@"/"))
                        {
                            var regex = WildcardToRegex(includePattern);
                            includeFiles.InsertRange(0,
                                Directory.GetFiles(directoryPath, "*", SearchOption.AllDirectories)
                                    .Where(x => Regex.IsMatch(x, regex)));
                            ;
                        }
                        else
                        {
                            includeFiles.InsertRange(0,
                                Directory.GetFiles(directoryPath, includePattern, SearchOption.AllDirectories));
                        }

                    }
                }
                var exludeFiles= new List<string>();
                if (!string.IsNullOrEmpty(excludePatterns))
                {
                    foreach (var excludePattern in excludePatterns.Split(','))
                    {

                        if (excludePattern.Contains(@"/") || excludePattern.Contains(@"\"))
                        {
                            var regex = WildcardToRegex(excludePattern);
                            exludeFiles.InsertRange(0,
                                Directory.GetFiles(directoryPath, "*", SearchOption.AllDirectories)
                                    .Where(x => Regex.IsMatch(x, regex)));
                        }
                        else
                        {
                            exludeFiles.InsertRange(0,
                                Directory.GetFiles(directoryPath, excludePattern, SearchOption.AllDirectories));
                        }
                    }
                }
                fileInfos = includeFiles.Except(exludeFiles)
                    .Select(x=> new FileInfo(x)).ToList();
            }

            return fileInfos;
        }
开发者ID:jroquelaure,项目名称:tfs-plugin-artifactory,代码行数:60,代码来源:MatchArtifactHelper.cs

示例5: ToByteArray

 private byte[] ToByteArray()
 {
     List<byte> messageBytes = new List<byte>();
     foreach (STUNAttributeTLV attribute in this.Attributes)
     {   
         messageBytes.InsertRange(messageBytes.Count, attribute.Bytes);
         MessageHeader.Length += attribute.Length;
     }
     messageBytes.InsertRange(0, MessageHeader.Bytes);
     return messageBytes.ToArray();
 }
开发者ID:ludarous,项目名称:Netificator,代码行数:11,代码来源:STUNMessage.cs

示例6: Main

        public static void Main(string[] args)
        {
            Dictionary<string,int> dict=new Dictionary<string,int>();
            dict.Add("one",1);
            dict.Add("two",2);
            dict.Add("three",3);
            dict.Add("four",4);
            dict.Remove("one");

            Console.WriteLine(dict.ContainsKey("dsaf"));
            Console.WriteLine("Key Value Pairs after Dictionary related operations:");
            foreach (var pair in dict)
            {
                Console.WriteLine("{0}, {1}",
                    pair.Key,
                    pair.Value);
            }
            dict.Clear ();

            List<string> strList = new List<string> ();
            strList.Add ("one");
            strList.Add ("two");
            strList.Add ("three");
            strList.Add ("four");
            strList.Add ("five");
            strList.Insert (3, "great");
            string[] newList = new string[3]{ "ten", "eleven", "twelve" };
            strList.AddRange (newList);
            strList.InsertRange (3, newList);

            Console.WriteLine ("Output after all list related  operations i.e. add, insert, addrange, insertrange,remove");
            foreach (var i in strList)
                Console.WriteLine (i);
        }
开发者ID:ctsxamarintraining,项目名称:cts458703,代码行数:34,代码来源:Program.cs

示例7: Main

 public static void Main () {
     List<int> array = new List<int> { 1, 2, 3 };
     List<int> array2 = new List<int> { 4, 5, 6 };
     array.InsertRange(1, array2);
     foreach (var member in array)
         Console.WriteLine(member);
 }
开发者ID:cbsistem,项目名称:JSIL,代码行数:7,代码来源:Issue676.cs

示例8: Write

        public byte[] Write(ScenarioFile file)
        {
            var scenarioData = new List<byte>();

            scenarioData.AddRange(Encoding.ASCII.GetBytes("SCENARIO\r\n"));
            scenarioData.AddRange(BitConverter.GetBytes(Version));
            scenarioData.AddRange(BitConverter.GetBytes(file.ContentFiles.Count));

            file.ContentFiles[0] = CreateAreaSubFile(file.ZoneData);

            var ndfBinWriter = new NdfbinWriter();
            file.ContentFiles[1] = ndfBinWriter.Write(file.NdfBinary, false);

            foreach (var contentFile in file.ContentFiles)
            {
                scenarioData.AddRange(BitConverter.GetBytes(contentFile.Length));
                scenarioData.AddRange(contentFile);
            }

            byte[] hash = MD5.Create().ComputeHash(scenarioData.ToArray());

            scenarioData.InsertRange(10, hash.Concat(new byte[] { 0x00, 0x00 }));

            return scenarioData.ToArray();
        }
开发者ID:Scrivener07,项目名称:moddingSuite,代码行数:25,代码来源:ScenarioWriter.cs

示例9: PosTest2

    public bool PosTest2()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest2: Insert the collection to the beginning of the list");

        try
        {
            string[] strArray = { "apple", "dog", "banana", "chocolate", "dog", "food" };
            List<string> listObject = new List<string>(strArray);
            string[] insert = { "Hello", "World" };
            listObject.InsertRange(0, insert);
            if (listObject.Count != 8)
            {
                TestLibrary.TestFramework.LogError("003", "The result is not the value as expected,Count is: " + listObject.Count);
                retVal = false;
            }
            if ((listObject[0] != "Hello") || (listObject[1] != "World"))
            {
                TestLibrary.TestFramework.LogError("004", "The result is not the value as expected");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("005", "Unexpected exception: " + e);
            retVal = false;
        }

        return retVal;
    }
开发者ID:l1183479157,项目名称:coreclr,代码行数:31,代码来源:listinsertrange.cs.cs

示例10: PosTest1

    public bool PosTest1()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest1: The generic type is int");

        try
        {
            int[] iArray = { 0, 1, 2, 3, 8, 9, 10, 11, 12, 13, 14 };
            List<int> listObject = new List<int>(iArray);
            int[] insert = { 4, 5, 6, 7 };
            listObject.InsertRange(4, insert);
            for (int i = 0; i < 15; i++)
            {
                if (listObject[i] != i)
                {
                    TestLibrary.TestFramework.LogError("001", "The result is not the value as expected,listObject is: " + listObject[i]);
                    retVal = false;
                }
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("002", "Unexpected exception: " + e);
            retVal = false;
        }

        return retVal;
    }
开发者ID:l1183479157,项目名称:coreclr,代码行数:29,代码来源:listinsertrange.cs.cs

示例11: Main

        static void Main(string[] args)
        {
            List<string> words = new List<string>(); // New string-typed list
            words.Add("melon");
            words.Add("avocado");
            words.AddRange(new[] { "banana", "plum" });
            words.Insert(0, "lemon"); // Insert at start
            words.InsertRange(0, new[] { "peach", "nashi" }); // Insert at start
            words.Remove("melon");
            words.RemoveAt(3); // Remove the 4th element
            words.RemoveRange(0, 2); // Remove first 2 elements
            words.RemoveAll(s => s.StartsWith("n"));// Remove all strings starting in 'n'
            Console.WriteLine(words[0]); // first word
            Console.WriteLine(words[words.Count - 1]); // last word
            foreach (string s in words) Console.WriteLine(s); // all words
            List<string> subset = words.GetRange(1, 2); // 2nd->3rd words
            string[] wordsArray = words.ToArray(); // Creates a new typed array
            string[] existing = new string[1000];// Copy first two elements to the end of an existing array
            words.CopyTo(0, existing, 998, 2);
            List<string> upperCastWords = words.ConvertAll(s => s.ToUpper());
            List<int> lengths = words.ConvertAll(s => s.Length);

            ArrayList al = new ArrayList();
            al.Add("hello");
            string first = (string)al[0];
            string[] strArr = (string[])al.ToArray(typeof(string));
            List<string> list = al.Cast<string>().ToList();
        }
开发者ID:PhilTheAir,项目名称:CSharp,代码行数:28,代码来源:ListArrayList.cs

示例12: ExpandControlFlowExpressions

        public List<AphidExpression> ExpandControlFlowExpressions(List<AphidExpression> ast)
        {
            var ast2 = new List<AphidExpression>(ast);

            var ifs = ast
                .Select(x => new
                {
                    Expression = x,
                    Expanded = ExpandControlFlowExpressions(x),
                })
                .Where(x => x.Expanded != null)
                .ToArray();

            foreach (var expandedIf in ifs)
            {
                var i = ast2.IndexOf(expandedIf.Expression);
                ast2.RemoveAt(i);
                ast2.InsertRange(i, expandedIf.Expanded);
            }

            if (AnyControlFlowExpressions(ast2))
            {
                return ExpandControlFlowExpressions(ast2);
            }
            else
            {
                //foreach (var n in ast.OfType<IParentNode>())
                //{
                //    ExpandControlFlowExpressions(n.GetChildren().ToList());
                //}

                return ast2;
            }
        }
开发者ID:John-Leitch,项目名称:Blue-Racer-CPU,代码行数:34,代码来源:AphidPreprocessor.cs

示例13: CombineFiles

    public static byte[] CombineFiles(FileEx[] data)
    {
        List<byte> result = new List<byte>();

            // Generating the header
            int pos = 0;
            string toAdd  = "";
            foreach(var file in data)
            {
                int future = pos + file.data.Length;
                toAdd += string.Format("[|{0}|{1}|{2}|]", file.name, pos, file.data.Length);
                pos = future;
            }
            result.AddRange(GetBytes(toAdd));

            //Adding the header's size
            result.InsertRange(0, BitConverter.GetBytes(result.Count));

            //Adding the file data
            foreach(var file in data)
            {
                result.AddRange(file.data);
            }
            return result.ToArray();
    }
开发者ID:Syriamanal,项目名称:xprotect,代码行数:25,代码来源:FileHandle.cs

示例14: Send

        public void Send(string name, string content)
        {
            // Sends text EV3Packet in this format:

            // bbbbmmmmttssllaaaLLLLppp
            // bbbb = bytes in the message, little endian
            // mmmm = message counter
            // tt   = 0×81
            // ss   = 0x9E
            // ll   = mailbox name length INCLUDING the \0 terminator
            // aaa… = mailbox name, should be terminated with a \0
            // LLLL = payload length INCLUDING the , little endian
            // ppp… = payload, should be terminated with the \0

            List<byte> MessageHeaderList = new List<byte>();

            MessageHeaderList.AddRange(new byte[] { 0x00, 0x01, 0x81, 0x9E }); // mmmmm + tt + ss
            List<byte> by = BitConverter.GetBytes((Int16)(name.Length + 1)).Reverse().ToList();
            by.RemoveAt(0);
            MessageHeaderList.AddRange(by.ToArray()); // ll
            MessageHeaderList.AddRange(Encoding.ASCII.GetBytes(name)); // aaa…
            MessageHeaderList.AddRange(new byte[] { 0x00 }); // \0
            MessageHeaderList.AddRange(BitConverter.GetBytes((Int16)(content.Length + 1))); // LLLL
            MessageHeaderList.AddRange(Encoding.ASCII.GetBytes(content)); // ppp…
            MessageHeaderList.AddRange(new byte[] { 0x00 }); // \0
            MessageHeaderList.InsertRange(0, BitConverter.GetBytes((Int16)(MessageHeaderList.Count))); // bbbb

            EV3ComPort.Write(MessageHeaderList.ToArray(), 0, MessageHeaderList.ToArray().Length);
        }
开发者ID:rjonda,项目名称:RemoteEV3,代码行数:29,代码来源:EV3Sender.cs

示例15: GetAllDirectories

        // Method to retrieve all directories, recursively, within a store.
        public static List<String> GetAllDirectories(string pattern, IsolatedStorageFile storeFile)
        {
            // Get the root of the search string.
            string root = Path.GetDirectoryName(pattern);

            if (root != "")
            {
                root += "/";
            }

            // Retrieve directories.
            List<String> directoryList = new List<String>(storeFile.GetDirectoryNames(pattern));

            // Retrieve subdirectories of matches.
            for (int i = 0, max = directoryList.Count; i < max; i++)
            {
                string directory = directoryList[i] + "/";
                List<String> more = GetAllDirectories(root + directory + "*", storeFile);

                // For each subdirectory found, add in the base path.
                for (int j = 0; j < more.Count; j++)
                {
                    more[j] = directory + more[j];
                }

                // Insert the subdirectories into the list and
                // update the counter and upper bound.
                directoryList.InsertRange(i + 1, more);
                i += more.Count;
                max += more.Count;
            }

            return directoryList;
        }
开发者ID:NBitionDevelopment,项目名称:WindowsPhoneFeedBoard,代码行数:35,代码来源:FileHelper.cs


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