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


C# System.Collections.ArrayList.Cast方法代码示例

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


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

示例1: btnCast_Click

        private void btnCast_Click(object sender, EventArgs e)
        {
            listBox1.Items.Clear();
            System.Collections.ArrayList TestCast = new System.Collections.ArrayList();
            TestCast.Add("Test1");
            TestCast.Add("Test2");
            TestCast.Add("Test3");

            IEnumerable<string> query =
                TestCast.Cast<string>().OrderBy(n => n).Select(n => n);
            foreach (var n in query)
            {
                listBox1.Items.Add("Cast : " + n);
            }

            int[] numbers = { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 };
            string[] strings = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" };

            var textNums = from n in numbers
                           select strings[n];

            foreach (var n in textNums)
            {
                listBox1.Items.Add("Select : " + n);
            }
        }
开发者ID:TeerapongSSD,项目名称:Training_C_Sharp,代码行数:26,代码来源:frmLinq.cs

示例2: Untyped

        static void Untyped()
        {
            var list = new System.Collections.ArrayList(Formula1.GetChampions() as System.Collections.ICollection);

            var query = from r in list.Cast<Racer>()
                        where r.Country == "USA"
                        orderby r.Wins descending
                        select r;
            foreach (var racer in query)
            {
                Console.WriteLine("{0:A}", racer);
            }

        }
开发者ID:ChegnduJackli,项目名称:Projects,代码行数:14,代码来源:Program.cs

示例3: button30_Click

        private void button30_Click(object sender, EventArgs e)
        {
            System.Collections.ArrayList arrList = new System.Collections.ArrayList();

            arrList.Add(new Point(100, 100));
            arrList.Add(new Point(100, 100));

            //((Point) arrList[0]).X

            var q = from p in arrList.Cast<Point>()
                    select p;

            this.dataGridView1.DataSource = q.ToList();
        }
开发者ID:YiYingChuang,项目名称:LinQ,代码行数:14,代码来源:3.+FrmLINQ架構介紹_InsideLINQ.cs

示例4: CreateArrayWithSingleItemIfNotExcluded


//.........这里部分代码省略.........
                            //    keep the exclude search, but don't do any processing on it while recursing until the baseDirectory
                            //    in the recursion matches the exclude BaseDirectory.  Examples:
                            //      - Include - Exclude
                            //      - C:\git\msbuild\ - c:\git\msbuild\obj\
                            //      - C:\git\msbuild\ - c:\git\msbuild\src\Common\

                            if (searchesToExcludeInSubdirs == null)
                            {
                                searchesToExcludeInSubdirs = new Dictionary<string, List<RecursionState>>();
                            }
                            List<RecursionState> listForSubdir;
                            if (!searchesToExcludeInSubdirs.TryGetValue(excludeState.BaseDirectory, out listForSubdir))
                            {
                                listForSubdir = new List<RecursionState>();

                                searchesToExcludeInSubdirs[excludeState.BaseDirectory] = listForSubdir;
                            }
                            listForSubdir.Add(excludeState);
                        }
                        else
                        {
                            //  Exclude base directory length is less than include base directory length.
                            if (!state.BaseDirectory.StartsWith(excludeState.BaseDirectory))
                            {
                                //  Include path is longer, but doesn't start with the exclude path.  So ignore exclude path
                                //  (since it won't match anything under the include path)
                                continue;
                            }

                            //  Now check the wildcard part
                            if (excludeState.RemainingWildcardDirectory.Length == 0)
                            {
                                //  The wildcard part is empty, so ignore the exclude search, as it's looking for files non-recursively
                                //  in a folder higher up than the include baseDirectory.
                                //  Example: include="c:\git\msbuild\src\Framework\**\*.cs" exclude="c:\git\msbuild\*.cs"
                                continue;
                            }
                            else if (excludeState.RemainingWildcardDirectory == recursiveDirectoryMatch + s_directorySeparator)
                            {
                                //  The wildcard part is exactly "**\", so the exclude pattern will apply to everything in the include
                                //  pattern, so simply update the exclude's BaseDirectory to be the same as the include baseDirectory
                                //  Example: include="c:\git\msbuild\src\Framework\**\*.*" exclude="c:\git\msbuild\**\*.bak"
                                excludeState.BaseDirectory = state.BaseDirectory;
                                searchesToExclude.Add(excludeState);
                            }
                            else
                            {
                                //  The wildcard part is non-empty and not "**\", so we will need to match it with a Regex.  Fortunately
                                //  these conditions mean that it needs to be matched with a Regex anyway, so here we will update the
                                //  BaseDirectory to be the same as the exclude BaseDirectory, and change the wildcard part to be "**\"
                                //  because we don't know where the different parts of the exclude wildcard part would be matched.
                                //  Example: include="c:\git\msbuild\src\Framework\**\*.*" exclude="c:\git\msbuild\**\bin\**\*.*"
                                Debug.Assert(excludeState.SearchData.RegexFileMatch != null, "Expected Regex to be used for exclude file matching");
                                excludeState.BaseDirectory = state.BaseDirectory;
                                excludeState.RemainingWildcardDirectory = recursiveDirectoryMatch + s_directorySeparator;
                                searchesToExclude.Add(excludeState);
                            }
                        }
                    }
                    else
                    {
                        searchesToExclude.Add(excludeState);
                    }
                }
            }

            if (searchesToExclude != null && searchesToExclude.Count == 0)
            {
                searchesToExclude = null;
            }

            /*
             * Now get the files that match, starting at the lowest fixed directory.
             */
            try
            {
                GetFilesRecursive(listOfFiles, state,
                   projectDirectoryUnescaped, stripProjectDirectory, getFileSystemEntries, searchesToExclude, searchesToExcludeInSubdirs);
            }
            catch (Exception ex) when (ExceptionHandling.IsIoRelatedException(ex))
            {
                // Assume it's not meant to be a path
                return CreateArrayWithSingleItemIfNotExcluded(filespecUnescaped, excludeSpecsUnescaped);
            }

            /*
             * Build the return array.
             */

            string[] files;
            if (resultsToExclude != null)
            {
                files = arrayListOfFiles.Cast<string>().Where(f => !resultsToExclude.Contains(f)).ToArray();
            }
            else
            {
                files = (string[])arrayListOfFiles.ToArray(typeof(string));
            }
            return files;
        }
开发者ID:nikson,项目名称:msbuild,代码行数:101,代码来源:FileMatcher.cs


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