Guest User

Guest User

  • Tech Writer
  • 189
  • 25k

Index and length must refer to a location within the string.

Jun 22 2018 12:51 AM
  1. private bool isvalidyearcode(string ycode)  
  2.        {  
  3.            if (Convert.ToInt32(ycode.Substring(1, 4).ToString()) == 0 | Convert.ToInt32(ycode.Substring(3, 2).ToString()) + 1 != Convert.ToInt32(ycode.Substring(6, 7).ToString()) | Convert.ToInt32(ycode.Substring(5, 1)).ToString() != "-")  //error
  4.            {  
  5.                MessageBox.Show("Invalid Year code");  
  6.                return false;     
  7.            }          
  8.            return true;  
  9.        }  

Answers (4)