Index and length must refer to a location within the string when I try to add an extra digit? : <p>Hello so I have a program that generates a Key when you fill in some info in some text boxes. When ever I generate a key that adds an extra 1 or 0 it tells me Index and length must refer to a location within the string, this is the code: </p>

<pre><code>public virtual string GenerateKey(string BreedPub)
        {
                return GenerateKey() + BreedPub.Substring(0, 3);
        }
</code></pre>

<p>and I think it's conflicting with this:</p>

<pre><code>public override string GenerateKey(string BreedPub)
        {
            string key = null;
            if (Pedigree == "1")
            {
                key = GenerateKey() + BreedPub.Substring(0, 3) + "1";
            }
            else
            {
                key = GenerateKey() + BreedPub.Substring(0, 3) + "0";
            }
            return key;
</code></pre>

<p>now i've tried to change the substring to (0,4) or doing this:</p>

<pre><code>public virtual string GenerateKey(string BreedPub)
        {
            if (Pedigree == "1")
            {
                return GenerateKey() + BreedPub.Substring(0, 3) + "1";
            }
            else if (Pedigree == "0")
            {
                return GenerateKey() + BreedPub.Substring(0, 3) + "0";
            }
            else
            {
                return GenerateKey() + BreedPub.Substring(0, 3);
            }
        }
</code></pre>

<p>but it still gives me the same error message, what could I be doing wrong?</p>
