Search code examples
c#tryparserequest.form

What is TryParse and Request.Form doing in this line of C# code?


What does this line of code do? I'm relatively new to C# and I've been trying to figure it out by reading about TryParse and Request.Form, however, I think a more comprehensive explanation would help me.

int.TryParse(Request.Form["yearhidden"], out year);


Solution

  • TryParse is taking the value from Request.Form["yearhidden"]

    Request.Form["yearhidden"] is a form field in your html called yearhidden.

    TryParse then attempts to parse it into an integer value. It returns True if it was successful, False if not.

    The value is stored in the variable year