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

Shell: Checking if argument exists and matches expression

regex bash shell

I'm new to shell scripting and trying to write the ability to check if an argument exists and if it matches an expression. I'm not sure how to write expressions, so this is what I have so far:

Rails 4: use different server port depending on environment

ruby-on-rails ruby-on-rails-4 environment-variables boot

I'm trying to automate the configuration of my rails application and I want to be able to start the app without specifying the port, as I would like it to be chosen depending on the environment.

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.