C# 回调函数的用法

public class CADHelper

{

public  delegate Coordinate ConverCoordinate(Coordinate oldcoord);

public static  Coordinate DoConverCoordinate(Coordinate coord, ConverCoordinate convert)

{

//List<Coordinate> coordinates = new List<Coordinate>() { new Coordinate() { X = 1, Y = 2 }, new Coordinate() { X = 2, Y = 4 } };

return convert(coord);

}

}

public class Coordinate

{

public double X { get; set; }

public double Y { get; set; }

}

public class CoordConvert

{

public static Coordinate Convert(Coordinate coordinate)

{

Coordinate result = new Coordinate();

result.X = coordinate.X + 1000;

result.Y = coordinate.Y + 1000;

return result;

}

}

void mian()

{

List<Coordinate> coordinates = new List<Coordinate>() { new Coordinate() { X = 1, Y = 2 }, new Coordinate() { X = 2, Y = 4 } };

Coordinate coordinate= CADHelper.DoConverCoordinate(coordinates[1], CoordConvert.Convert);

console.writeline(string.Format("X:{0}    Y:{1}", coordinate.X, coordinate.Y));

}

(0)

相关推荐