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);


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

Request.Form provides the form element posted to the HTTP request.

int.TryParse attempts to take this value and convert it to an integer.

In this case, you're taking the "yearhidden" form element's value, and attempting to convert it to an integer, which gets set in the year variable.

Note that you'd typically check the return value of int.TryParse, and handle the case where a non-numeric value was passed into the yearhidden variable.

int.TryParse returns a boolean that represents whether or not the method was able to parse the first parameter, Request.Form["yearhidden"], into an integer.

If it is able to successfully parse the value, the value of the second parameter, year, will be set to the value.

Request.Form contains all of the information within an html form element that was sent in a given request.

out is a keyword that forces arguments to be passed by reference.


Need Your Help

Endless “loading” of the page due to JQuery script. How to solve it?

javascript jquery html performance pageload

My page stays in an endless loading state due to my "emoji.js" script (Google Chrome testing). The endless loading disables the "emoji" smileys from appearing and you see them in their text code. But

Unwrap XPCNativeWrapper object in Firefox versions < 3.6.2

javascript firefox-addon wrapper

Is there a way to unwrap an XPCNativeWrapper object in early versions of Firefox (before version 3.6.2)?

Create diectory (ftp_mkdir) only if files exist

php ftp directory

I currently have a program that connects to an ftp directory, if it finds csv files, runs a script, then after the script has run on the files, it creates a back up folder with the date and moves t...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.