CKTIS / C#
numeric types: practical reference
numeric types: practical reference: Numeric types differ in range, precision, representation, and overflow rules.
Version: C# language and .NET 10 reference runtime
Syntax
// numeric typesNumeric types differ in range, precision, representation, and overflow rules.
Choose int or long for integers, decimal for money, and double for scientific computation.
Implicit conversions and rounding can lose information.
NaN, infinity, MinValue, and overflow require boundary tests.
The complete program actually uses numeric types; its exact expected stdout is 9.5.
Examples
using System;
using System.Buffers;
using System.Collections.Concurrent;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
using Number = System.Int32;
int whole = 7; decimal money = 2.5m; Console.WriteLine((whole + money).ToString(CultureInfo.InvariantCulture));
Result
9.5
The complete program actually uses `numeric types`; its exact expected stdout is `9.5`.