本文整理汇总了C#中System.Converter<TInput,TOutput>代理的典型用法代码示例。如果您正苦于以下问题:C# Converter<TInput,TOutput>代理的具体用法?C# Converter<TInput,TOutput>怎么用?C# Converter<TInput,TOutput>使用的例子?那么恭喜您, 这里精选的代理代码示例或许可以为您提供帮助。
Converter<TInput,TOutput>代理属于System命名空间,在下文中一共展示了Converter<TInput,TOutput>代理的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
//引入命名空间
using System;
using System.Drawing;
using System.Collections.Generic;
public class Example
{
public static void Main()
{
// Create an array of PointF objects.
PointF[] apf = {
new PointF(27.8F, 32.62F),
new PointF(99.3F, 147.273F),
new PointF(7.5F, 1412.2F) };
// Display each element in the PointF array.
Console.WriteLine();
foreach( PointF p in apf )
Console.WriteLine(p);
// Convert each PointF element to a Point object.
Point[] ap = Array.ConvertAll(apf,
new Converter<PointF, Point>(PointFToPoint));
// Display each element in the Point array.
Console.WriteLine();
foreach( Point p in ap )
{
Console.WriteLine(p);
}
}
public static Point PointFToPoint(PointF pf)
{
return new Point(((int) pf.X), ((int) pf.Y));
}
}
输出:
{X=27.8, Y=32.62} {X=99.3, Y=147.273} {X=7.5, Y=1412.2} {X=27,Y=32} {X=99,Y=147} {X=7,Y=1412}
示例2: Main
//引入命名空间
using System;
using System.Drawing;
using System.Collections.Generic;
public class Example
{
public static void Main()
{
List<PointF> lpf = new List<PointF>();
lpf.Add(new PointF(27.8F, 32.62F));
lpf.Add(new PointF(99.3F, 147.273F));
lpf.Add(new PointF(7.5F, 1412.2F));
Console.WriteLine();
foreach( PointF p in lpf )
{
Console.WriteLine(p);
}
List<Point> lp = lpf.ConvertAll(
new Converter<PointF, Point>(PointFToPoint));
Console.WriteLine();
foreach( Point p in lp )
{
Console.WriteLine(p);
}
}
public static Point PointFToPoint(PointF pf)
{
return new Point(((int) pf.X), ((int) pf.Y));
}
}
输出:
{X=27.8, Y=32.62} {X=99.3, Y=147.273} {X=7.5, Y=1412.2} {X=27,Y=32} {X=99,Y=147} {X=7,Y=1412}