Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6341469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:02:29+00:00 2026-05-24T20:02:29+00:00

I use this simple method to retrieve a Query String from a Page a

  • 0

I use this simple method to retrieve a Query String from a Page a returning a Int. In case a valid Id can not be found I would like return a default value int 0.

I would like to know if there is a better way to write this method, in details:

  • Would be better use just a single return statement instead the two? If yes what is the best way to do it?
  • Shall I perform any other checking when retrieving the Query String?
protected int GetPageIndex()
{
    int output;
    bool result = Int32.TryParse(Request.QueryString["page"], out output);
    if(result)
        return output;
    return output = 0; // Return Default value
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T20:02:30+00:00Added an answer on May 24, 2026 at 8:02 pm

    Just initialize it before you try to parse it… Anyways, Int32.TryParse sets the value to 0 if the conversion is unsuccessful… 🙂 http://msdn.microsoft.com/en-us/library/f02979c7.aspx

    protected int GetPageIndex()
        {
            int output = 0;
            Int32.TryParse(Request.QueryString["page"], out output);
            return output;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Simple. If I use: public void Add(params int[] values) Then I can use this
I know how to get the scrollTop of a page, I use this simple
In order to delete all .svn files/folders/subfolders in myfolder I use this simple line
I use this code: http://blogswizards.com/plugin-development/sliding-boxes-and-captions-with-jquery On a simple gallery site I am building. Specifically
I have developed a simple library in Ruby and need to use this in
I've got this simple Perl script: #! /usr/bin/perl -w use strict; use Data::Dumper; my
This question is simple. What function would I use in a PHP script to
For a very simple profiling I use microtime() like this: $now = microtime(); for
For more information see this Example use strict; use warnings; use CGI::Simple; use DBI;
I'm trying to retrieve a Web page, and apply a simple regular expression on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.