title: Remainder operator in C# perform different than MOD in Visual Basic
body: <p>I have found a strange situation converting a piece of code from C# to VB.NET, the code is a small class that convert from base 10 to base 36 and vice versa.</p>
  
  <p>the key point is this function : </p>
  
  <pre><code>    /// &lt;summary&gt;
      /// A Base36 De- and Encoder
      /// &lt;/summary&gt;
      public static class Base36
      {
          private const string CharList = "0123456789abcdefghijklmnopqrstuvwxyz";
  
          /// &lt;summary&gt;
          /// Encode the given number into a Base36 string
          /// &lt;/summary&gt;
          /// &lt;param name="input"&gt;&lt;/param&gt;
          /// &lt;returns&gt;&lt;/returns&gt;
          public static String Encode(long input)
          {
              if (input &lt; 0) throw new ArgumentOutOfRangeException("input", input, "input cannot be negative");
  
              char[] clistarr = CharList.ToCharArray();
              var result = new Stack&lt;char&gt;();
              while (input != 0)
              {
                  result.Push(clistarr[input % 36]);
                  input /= 36;
              }
              return new string(result.ToArray());
          }
  </code></pre>
  
  <p>that converted in VB.NET should result in : </p>
  
  <pre class="lang-vb prettyprint-override"><code>Public NotInheritable Class Base36
      Private Sub New()
      End Sub
      Private Const CharList As String = "0123456789abcdefghijklmnopqrstuvwxyz"
  
      ''' &lt;summary&gt;
      ''' Encode the given number into a Base36 string
      ''' &lt;/summary&gt;
      ''' &lt;param name="input"&gt;&lt;/param&gt;
      ''' &lt;returns&gt;&lt;/returns&gt;
      Public Shared Function Encode(input As Int64) As String
          If input &lt; 0 Then
              Throw New ArgumentOutOfRangeException("input", input, "input cannot be negative")
          End If
  
          Dim clistarr As Char() = CharList.ToCharArray()
          Dim result = New Stack(Of Char)()
          While input &lt;&gt; 0
              result.Push(clistarr(input Mod 36))
              input /= 36
          End While
          Return New String(result.ToArray())
      End Function
  </code></pre>
  
  <p>The problem is that the modulo operator in VB.NET perform differently that the % remainder operator in C#, in fact if you call the encode method in C# : </p>
  
  <pre><code>        long l = 13072113072399; 
          string result = Base36.Encode(l);   //Result is : 4mt8um0b3
  </code></pre>
  
  <p>while calling the method in C# : </p>
  
  <pre><code>    Dim l As Int64 = 13072113072399
      Dim result As String = Base36.Encode(l) //Result is : 5nujsu3ar
  </code></pre>
  
  <p>The responsible of the difference is the different result that the modulo operator return in some situations, why ?</p>
  
  <p>What is the equivalent of the % remainder operator in VB.NET ?</p>