本文整理汇总了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);
}
}
示例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);
}
}
示例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();
}
示例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;
}