Skip to content

Instantly share code, notes, and snippets.

@jumperson
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jumperson/9379483 to your computer and use it in GitHub Desktop.
Save jumperson/9379483 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace RunRun
{
public class Jone
{
public static void Run()
{
var a = new Complex(2.0, 5.0);
var b = new Complex(3.0, 1.0);
var r_a = a + b;
var r_b = a - b;
var r_c = a + 2.5;
//var r_d = a + new Tuple<Double, Double>(2.5, 3.0);
var r_d = a + Tuple.Create(2.5, 3.0);
}
private class Complex
{
private Double real { get; set; }
private Double imag { get; set; }
public Complex(Double r, Double i)
{
this.real = r;
this.imag = i;
}
public static Complex operator +(Complex val1,Complex val2)
{
return new Complex(val1.real + val2.real, val1.imag + val2.imag);
}
public static Complex operator -(Complex val1, Complex val2)
{
return new Complex(val1.real - val2.real, val1.imag - val2.imag);
}
public override string ToString()
{
return this.real + "+" + this.imag + "i";
}
public static implicit operator Complex(Double val)
{
return new Complex(val, 0);
}
public static implicit operator Complex(Tuple<Double,Double> val)
{
return new Complex(val.Item1,val.Item2);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment