Skip to content

Instantly share code, notes, and snippets.

@nelsonlaquet
Created May 5, 2011 21:40
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 nelsonlaquet/958026 to your computer and use it in GitHub Desktop.
Save nelsonlaquet/958026 to your computer and use it in GitHub Desktop.
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