How to Reverse an Array in C# (8 Methods with Examples)

Reverse an array in C#: TX, CA, NY, FL becomes FL, NY, CA, TX with Array.Reverse(states)

Your sales report lists January first, but the dashboard wants the newest month on top. To reverse an array in C#, call Array.Reverse(arr). It flips the array in place in one line. In this tutorial, I’ll walk through eight ways to reverse an array in C#, from the built-in method to loops that skip Reverse() … Read more >>

How to Convert Object to JSON Without Escape Characters in C#

Convert object to JSON without escape characters in C#: Tom u0026 Jerryu0027s becomes Tom & Jerry's with UnsafeRelaxedJsonEscaping

Most people who search convert object to JSON without escape characters C# just ran JsonSerializer.Serialize on a name like Tom & Jerry’s and got this back: Quick answer: set Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping in JsonSerializerOptions. Use it only for JSON sent as UTF-8, never inside an HTML page. I tested every fix on .NET 10 with … Read more >>

How to Convert String to Double in C#

Convert string to double in C#: "1,234.56" becomes 1234.56 with double.Parse and CultureInfo.InvariantCulture

The safest way to convert string to double in C# is double.TryParse with an explicit culture. It returns false on bad text instead of crashing: Every snippet below ran on .NET 10 against a 2026 fuel log, including blank input, European commas and numbers too big for a double. double.Parse: Convert a String to Double … Read more >>

How to Check for Null in C# (is null, ?., ??, Empty Objects)

Check for null in C#: an overloaded == operator makes cart == null print True while cart is null prints False

The usual way to check for null in C#, if (order == null), once skipped real orders in a client’s checkout. Their Order class overloaded ==, so an empty cart compared equal to null. Quick answer: write order is null or order is not null. The compiler never calls an overloaded operator for those patterns. … Read more >>

How to Convert Int to Binary String with Leading Zeros in C#

Convert int to binary string with leading zeros in C#: 10 formatted with ToString("B8") as eight bit boxes 00001010

To convert int to binary string with leading zeros in C#, call ToString(“B8”) on .NET 8 or later, or Convert.ToString(n, 2).PadLeft(8, ‘0’) on older frameworks: Quick answer: the number after B is the minimum digit count, so B8 turns 10 into 00001010. I ran both on .NET 10, plus negative numbers, nibble grouping and parsing … Read more >>