Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Math 扩展和重载MS和点类型_Math_C# 4.0_Overloading_Extend - Fatal编程技术网

Math 扩展和重载MS和点类型

Math 扩展和重载MS和点类型,math,c#-4.0,overloading,extend,Math,C# 4.0,Overloading,Extend,我是否有自己的点和向量类型来重载它们?为什么这不起作用 namespace System . windows { public partial struct Point : IFormattable { public static Point operator * ( Point P , double D ) { Point Po = new Point ( ); return Po; } } } namespace Silverligh

我是否有自己的点和向量类型来重载它们?为什么这不起作用

namespace System . windows
{
public partial struct Point : IFormattable
{
    public static Point operator * ( Point P , double D )
    {
        Point Po = new Point ( );
        return Po;
    }
}
}

namespace SilverlightApplication36
{
public partial class MainPage : UserControl
{

    public static void ShrinkingRectangle ( WriteableBitmap wBM , int x1 , int y1 , int x2 , int y2 , Color C )
    {
        wBM . DrawRectangle ( x1 , y1 , x2 , y2 , Colors . Red );
        Point Center = Mean ( x1 , y1 , x2 , y2 );
        wBM . SetPixel ( Center , Colors.Blue , 3 );
        Point P1 = new Point ( x1 , y1 );
        Point P2 = new Point ( x1 , y2 );
        Point P3 = new Point ( x1 , y2 );
        Point P4 = new Point ( x2 , y1 );
        const int Steps = 10;
        for ( int i = 0 ; i < Steps ; i++ )
        {
            double iF = (double)(i+1) / (double)Steps;
            double jF = ( 1.0 - iF );
            Point P11 = **P1 * jF;**
        }
    }
名称空间系统。窗户
{
公共部分结构点:可附加
{
公共静态点运算符*(点P,双D)
{
点Po=新点();
退回采购订单;
}
}
}
命名空间SilverlightApplication36
{
公共部分类主页面:UserControl
{
公共静态空白收缩矩形(可写位图wBM,int-x1,int-y1,int-x2,int-y2,C色)
{
wBM.DrawRectangle(x1、y1、x2、y2,颜色为红色);
点中心=平均值(x1,y1,x2,y2);
wBM.SetPixel(中心,颜色。蓝色,3);
点P1=新点(x1,y1);
点P2=新点(x1,y2);
点P3=新点(x1,y2);
点P4=新点(x2,y1);
const int Steps=10;
对于(int i=0;i
我真的不明白你想用这一行实现什么:

Point P11 = **P1 * jF;** 
如果您尝试为其通电,则使用该功能

更新 在结构中应该有一个表示值的内部字段,然后实现该运算符非常容易

至于
IFormattable
,我并没有真正测试我写的东西,我只是从中复制了代码,让您了解:

public partial struct Point : IFormattable
{
  private double x;
  public double X
  {
    get { return x; }
  }

  private double y;
  public double Y
  {
    get { return y; }
  }

  public static Point operator *(Point point, double value)
  {
    return new Point(point.X * value, point.y * value);
  }

  public Point(double x, double y)
  {
    this.x = x;
    this.y = y;
  }

  #region IFormattable Members

  public string ToString(string format, IFormatProvider formatProvider)
  {
    if (format == null) format = "H"; //hyphenized


    if (formatProvider != null)
    {
      ICustomFormatter formatter = 
        (ICustomFormatter)formatProvider.GetFormat(this.GetType());

      if (formatter != null)
        return formatter.Format(format, this, formatProvider);
    }

    switch (format)
    {
      case "X:
        return string.Format("{0}x{1}", X, Y);
      case "C":
        return string.Format("{0}, {1}", X, Y);
      case "H":
      default:
        return string.Format("{0}-{1}", X, Y); 
    }                                          
  }

  #endregion
}

具体来说,什么“不起作用”?我怀疑这只是为了在他的代码中显示关键行而进行的大胆突出显示…但我可能错了。起初我也有同样的WTF想法。:)精确地说仍然在修补。嘿,精确地说我输入了星星名称星星**精确地**好的,那么你的问题呢?问题解决了吗?如果解决了,请不要忘记投票/标记答案。