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

  • SEARCH
  • Home
  • 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 8080137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:19:30+00:00 2026-06-05T16:19:30+00:00

So I created a custom int.tryparse method in c# to try to make things

  • 0

So I created a custom int.tryparse method in c# to try to make things a little easier and cleaner looking. Here is the method:

    public static int? BoolIntParse(string number)
    {
        int temp;
        if (int.TryParse(number, out temp))
            return temp;
        else
            return null;
    }

Now, I would like to try to use it in this fashion:

if(int? someNumber = BoolIntParse(someString))
{
    //do some stuff if its a number
}
else
   //throw some error 

Which doesn’t seem to work. I also tried assigning the value before the condtional such as:

int? someNumber = BoolIntParse(someString);
if(someNumber)
{
    //do some stuff if its a number
}
else
   //throw some error 

And I get the error message Cannot implicitely convert type int? to bool

So this isn’t legal c#. Is this what a nullible int was designed for (this type of situation) or am I just not doing it correctly? I’m relatively new to c#.

  • 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-06-05T16:19:31+00:00Added an answer on June 5, 2026 at 4:19 pm

    You want to check if someNumber.HasValue. That should be in your conditional.

    if (someNumber.HasValue)

    or as an alternative, mentioned by @BrokenGlass:

    if (someNumber != null)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i create this custom actionlink public static IHtmlString CustomActionLink(this HtmlHelper htmlHelper, int userId, string
I created a custom exception public class InvalidUsernameException : ApplicationException { public InvalidUsernameException() {
I created custom adapter like this public class SettingsAdapter extends BaseAdapter{ ArrayList<String> Noptions =
I have created a custom ImageView and in its onDraw method I need to
I have the following method: public IEnumerable<Foo> GetFoo(int x, string y) { return from
I have created a custom view named MyDraw ,this is my MyDraw code, public
I've created a custom class to handle method calls from the server and I
I've created a custom UITableViewCell class, and used the layoutSubviews method to add a
I've created a custom layout to show gif animated image. Here is the code:
I created custom adapter for listview which contain text and images, on click of

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.