-3

The if condition is only checking for null or empty, this wouldn't fix the flaw. I want to check whether the Year string contains a number.

string Year = Request.Params[""year""];
if (Year == null || Year.Equals(""""))    
{    
    Year = System.DateTime.Now.Year.ToString();    
}
Kiran SK
  • 9
  • 1
  • 2
  • 6
  • 1
    possible duplicate of [How to identify if a string is a number?](http://stackoverflow.com/questions/894263/how-to-identify-if-a-string-is-a-number) – CodeCaster Sep 30 '15 at 10:32

2 Answers2

0

Use TryParse:

int x;
if (Year == null || Year.Equals("""") || !int.TryParse(Year, out x)){
     // your code

}
Maor Veitsman
  • 1,544
  • 9
  • 21
0

Try the following code. It will check if a string contains a numeric value enter image description

Manraj
  • 496
  • 2
  • 15