How to Convert String to DateTime in C#

Convert string to DateTime in C#: DateTime.Parse reads 03/04/2026 as March 4, 2026 with en-US and April 3, 2026 with en-GB

Here’s a bug we catch in code reviews every month: DateTime.Parse(“03/04/2026”) returns March 4 on a US server and April 3 on a UK one. Same line, two dates, no error. Quick answer: to convert string to DateTime in C#, always pass the culture: DateTime.Parse(text, CultureInfo.GetCultureInfo(“en-US”)). Use TryParse for user input and ParseExact when you … Read more >>

How to Convert a String to Int Without Parse in C#

Convert string to int without parse in C#: the string "4815" becomes the int 4815 through a c - '0' digit loop

Interviewers love this one: turn “4815” into an int without calling int.Parse. To convert a string to int without Parse in C#, loop over the characters and build the number yourself: In this tutorial, I’ll write my own convert string to int without parse in C# routine, then add a sign, invalid-character checks and overflow … Read more >>

How to Remove the Last Word from a String in C#

Remove the last word from a string in C#: LastIndexOf finds the last space in Trail Runner Jacket Navy and a range slice prints Trail Runner Jacket, with Navy as the last word

Picture a Portland outdoor store exporting 2,400 product titles for a new catalog. Every title ends with a color, like “Trail Runner Jacket Navy”, and the catalog wants only “Trail Runner Jacket”. That’s a textbook remove last word from string C# job, and the quickest answer is LastIndexOf(' ') plus a range slice up to … Read more >>

C# Constant Naming Conventions: PascalCase, Not ALL_CAPS (.NET 10)

C# constant naming convention: MAX_CART_ITEMS flagged by CA1707 becomes MaxCartItems in PascalCase

Our code reviews still catch MAX_CART_ITEMS in new C# code, usually from developers who came from Java, Python or C. Quick answer: the C# constant naming convention is PascalCase for every const, whether it’s public, private or local, with no underscore prefix: I tested this in a .NET 10 checkout for a Texas outdoor store, … Read more >>