String.IsNullOrEmpty and TryParse

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

Please do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.

This forum is for discussing mojoPortal development

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

You can monitor commits to the repository from this page. We also recommend developers to subscribe to email notifications in the developer forum as occasionally important things are announced.

Before posting questions here you might want to review the developer documentation.

Do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.
This thread is closed to new posts. You must sign in to post in the forums.
12/20/2006 9:53:34 PM
Gravatar
Total Posts 488

String.IsNullOrEmpty and TryParse

I have just noticed  that there are many blocks of code like this:

           int pageID = 0;
           if (HttpContext.Current.Request.Params["pageid"] != null)
            {
                if (HttpContext.Current.Request.Params["pageid"] != string.Empty)
                {
                    try
                    {
                        pageID = Int32.Parse(HttpContext.Current.Request.Params["pageid"]);
                    }
                    catch { }
                }
            }

Why not use the special functions in this case:

            int pageID = 0;
            if (!string.IsNullOrEmpty(HttpContext.Current.Request.Params["pageid"]))
            {
                Int32.TryParse(HttpContext.Current.Request.Params["pageid"], out pageID);
            }

or just

            int pageID;
            Int32.TryParse(HttpContext.Current.Request.Params["pageid"], out pageID);

?
12/21/2006 3:10:45 AM
Gravatar
Total Posts 18439

Re: String.IsNullOrEmpty and TryParse

yes, I agree. I've started to clean those up in a few places recently like ForumPostEdit.aspx but there are quite a few of them. FxCop pointed them out to me also because of the try catch. I want to eliminate any catching of general system.exception

Its a matter of priority, I have a lot of things going on at the moment and while this is not the cleanest code, its really not broken either.

If you want to work on some of those and send me patches, please feel free. I also want tomove things like that out of Page_Load and into private void LoadSettings() and then just call LoadSettings(); from page_load

Joe
You must sign in to post in the forums. This thread is closed to new posts.