C Sharp - Useful methods - 1 [ IsNumeric]

Deepak
Posted by in C# category on for Intermediate level | Views : 9002 red flag
Rating: 4 out of 5  
 1 vote(s)

IsNumeric
------------

Developer most of the time come across reusable codes. I have planned to collect all the reusable codes which come across my development experience and want to share with all.

This is one of the code which is always necessory
Introduction

IsNumebric

This method can be used in your application for checking the Numeric value.

 public static bool IsNumeric( object expression )
        {
            // Variable to collect the Return value of the TryParse method.
            bool isNumber;    
           
// Define variable to collect out parameter of the TryParse method. If the conversion fails, the out parameter is zero.
           double retNum;
           
            // The TryParse method converts a string in a specified style and culture-specific format to its double-precision floating point number equivalent.
            // The TryParse method does not generate an exception if the conversion fails. If the conversion passes, True is returned. If it does not, False is returned.
           
             isNumber = Double.TryParse( Convert.ToString( expression ) , System.Globalization.NumberStyles.Any , System.Globalization.NumberFormatInfo.InvariantInfo , out retNum );
            
          return isNumber;
        }
Page copy protected against web site content infringement by Copyscape

About the Author

Deepak
Full Name: Deepak Rao
Member Level: Starter
Member Status: Member
Member Since: 2/4/2009 10:10:50 PM
Country:

www.deepakrao.co.nr
I am an Indian Guy , working as Software Consultant in Bangalore . I am typical average programmer. One of those millions who earn their bread and butter from programming. I'm a software developer by profession, and I have a passion for books and music I am elder son to my parents, with an younger brother. Like most people, it's complicated thing to describe me. I am just inimitable, like many others. But I'll do the best I can to describe myself with words. I know that I am quite a smart person on most things, and also am exceedingly imaginative. I do feel that I am funny, though surely not everyone is funny all the time. My humor would probably best be labeled very wry and sarcastic, though it is quite fun to just plain laugh at the silliness of things lots of times.

Login to vote for this post.

Comments or Responses

Posted by: Raja on: 2/4/2009
Thanks for your Initiative Deepak. I went through all 4 posts and it's very useful and commonly used by all developers.

Please keep it up!!!

I feel your posts best fits in the Codes section rather than Articles, as these seems like Codes to achieve certain functionality.

Thanks



Login to post response

Comment using Facebook(Author doesn't get notification)