Created
May 5, 2011 21:40
-
-
Save nelsonlaquet/958026 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace ConsoleApplication61 | |
{ | |
class Vector | |
{ | |
public int X { get; private set; } | |
public Vector() { } | |
public Vector(int x) | |
{ | |
X = x; | |
} | |
public static Vector operator +(Vector lhs, Vector rhs) | |
{ | |
return new Vector(lhs.X + rhs.X); | |
} | |
} | |
class Foo | |
{ | |
private readonly string _worthless; | |
public Foo(string worthless) | |
{ | |
_worthless = worthless; | |
} | |
public static implicit operator Vector(Foo foo) | |
{ | |
return new Vector(foo._worthless.Length); | |
} | |
} | |
class Program | |
{ | |
static void Main() | |
{ | |
var vec1 = new Vector(1); | |
var vec2 = new Vector(3); | |
Console.WriteLine((vec1 + vec2).X); | |
var vec3 = new Vector(5); | |
var foo = new Foo("hello, world"); | |
Console.WriteLine((vec3 + foo).X); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment