Skip to content

C# Examples

  • Home
  • About C#
    • C# Interview Questions and Answers for .NET Developers
    • Learn C#: A Practical Path Through the Examples
  • All Posts
  • Bootstrap 5 Examples
  • Contact

C# .NET

Indent Strings with Spaces in C#

November 25, 2026June 26, 2014 by turgay

Indent text in C# with new string(‘ ‘, n), PadLeft, alignment in interpolated strings and IndentedTextWriter, including multi-line strings and columns.

Categories C# .NET, String Formatting Tags C#, indent string, indent string with spaces Leave a comment

Update the UI from Another Thread in C# (WinForms)

November 25, 2026June 25, 2014 by turgay

Fix “cross-thread operation not valid” in WinForms with async/await, IProgress and Control.Invoke or BeginInvoke, and know which one to use when.

Categories C# .NET, WinForms Tags C#, thread, update gui element, update label from another thread Leave a comment

Expose a Read-Only Collection in C# with AsReadOnly

November 25, 2026June 24, 2014 by turgay

Let callers read a private list without changing it, using AsReadOnly and IReadOnlyList, and why returning IEnumerable alone does not protect it.

Categories C# .NET Tags C#, read only collection, readonly wrapper collection Leave a comment

Email Validation in C#: Regex, MailAddress and Their Limits

November 25, 2026June 23, 2014 by turgay

Check that a string looks like an email address in C# with MailAddress.TryCreate or a simple source-generated regex, and why no regex can fully validate one.

Categories C# .NET Tags C#, email validation, regular expression Leave a comment

Disable or Hide the Close Button (X) on a Windows Form in C#

November 25, 2026June 23, 2014 by turgay

Gray out or remove the close button of a WinForms window with CreateParams or ControlBox, and stop the form from closing anyway with FormClosing.

Categories C# .NET, WinForms Tags C#, disable close button, hide close button 6 Comments
Older posts
Newer posts
← Previous Page1 … Page10 Page11 Page12 … Page17 Next →

Categories

Recent Posts

  • Select XML Nodes by Name or Attribute Value in C#
  • Binary Search Tree in C#: Add, Find, Remove and Traversals
  • Select, Insert, Update and Delete Data in an Access File with C#
  • C# Collections: Which One to Use and When
  • C# ArrayList vs Generic List: Examples and When to Use Each
  • About
  • Privacy Policy
  • Contact
© 2026 C# Examples