0

I have a variable

int? a = Int32.TryParse(b);

How can I make it that a becomes a null if b is found not to be an integer?

1
  • What do you want a’s value to be otherwise? Commented Oct 29, 2019 at 23:27

1 Answer 1

1

This should work for you

        int? a = int.TryParse(b, out var value) ? value : (int?) null;

you should use var instead of int?

        var a = int.TryParse(b, out var value) ? value : (int?) null;
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.