Skip to content

How to Check if an Object Is a Number in C#: .NET 11 update - #2435

Open
vladimir-pecanac-main wants to merge 1 commit into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/109062-csharp-how-to-check-if-an-object-is-a-number
Open

vladimir-pecanac-main wants to merge 1 commit into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/109062-csharp-how-to-check-if-an-object-is-a-number

Conversation

@vladimir-pecanac-main

Copy link
Copy Markdown
Collaborator

Moves both projects in numbers-csharp/CheckIfObjectIsNumber to net11.0 with current test packages (xunit 2.9.3, xunit.runner.visualstudio 4.0.1, Microsoft.NET.Test.Sdk 18.12.0, coverlet.collector 10.1.1). CheckIfShortUsingConvert now also catches InvalidCastException, so a value with no conversion returns false instead of crashing. IsNumber uses an or pattern instead of the || chain, a new ImplementsINumber method checks for any INumber<> type, Program.cs shows the new calls, and two new tests cover the generic method with a different numeric type and the INumber<> check.

…eption in the Convert check, add an INumber<> interface check
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant