title: C# compile time error if Int?
body: <p>I'm trying to <a href="https://stackoverflow.com/q/11430449/34537">recreate this</a> in C#.</p>
  
  <p>The problem i get is if i use constructors i MUST use new MyInt which i DO NOT WANT (to verbose). The way around it is to use the implicit/explicit operators. However they MUST be public... How the heck do i implement this in feature in C#? </p>
  
  <p>The short question is i'd like to pass byte/short into a function but not int. Passing int should get me a compile error. I know i can easily get runtime with a public implicit int operator. The code below shows that int is automatically converted to char</p>
  
  <p><a href="http://ideone.com/xPzU2" rel="nofollow noreferrer">Running sample</a> shows true</p>
  
  <pre><code>using System;
  class Program
  {
          public static void Write(MyInt v)
          {
                  Console.WriteLine("{0}", v.v is byte);
          }
          static void Main(string[] args)
          {
                  Write(2);
          }
  }
  public struct MyInt
  {
          public object v;
          public MyInt(byte vv) { v = vv; }
          public MyInt(short vv) { v = vv; }
          public MyInt(byte[] vv) { v = vv; }
          public static implicit operator MyInt(byte vv) { return new MyInt { v = vv }; }
          //public static extern implicit operator MyInt(int vv);
  }
  </code></pre>
  
  <p>Heres <a href="http://pastebin.com/btyH1FJJ" rel="nofollow noreferrer">more code which is useless</a>. It implements MyInt2/MyInt which isn't required in the C++ solution </p>