Skip to content
  • Home
  • About
  • No Access
  • Privacy Policy
Bits of .NET
Bits of .NET
  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy

Tag: Advanced C#

C#

C# Span and Memory: Zero-Copy Data Processing for Maximum Performance

- 19.08.26 - ErcanOPAK comment on C# Span and Memory: Zero-Copy Data Processing for Maximum Performance

Stop allocating new strings and arrays! Span<T> and Memory<T> let you work with data without copying, slashing GC pressure and memory usage. The Problem – Unnecessary Allocations: // Typical string processing string text = “Hello, World! Welcome to C#”; string[] words = text.Split(‘ ‘); // ❌ Allocates new array and strings foreach (var word in […]

Read More
C#

C#: Use Span for Zero-Allocation String Operations

- 19.03.26 | 19.03.26 - ErcanOPAK comment on C#: Use Span for Zero-Allocation String Operations

🚀 Zero-Copy Strings Substring creates new string (allocation). Span slices without copying. // ❌ Allocates memory string text = “Hello, World!”; string hello = text.Substring(0, 5); // New string // ✅ Zero allocation ReadOnlySpan span = text.AsSpan(); ReadOnlySpan hello = span.Slice(0, 5); // No copy! // Parsing without allocation ReadOnlySpan numbers = “123,456,789”.AsSpan(); var parts […]

Read More
C#

C#: Better Exception Messages with [CallerArgumentExpression]

- 28.02.26 - ErcanOPAK comment on C#: Better Exception Messages with [CallerArgumentExpression]

Ever get an exception and don’t know which variable was null? This attribute tells you the name of the expression passed to the method. public static void Guard(bool condition, [CallerArgumentExpression(“condition”)] string msg = null) { if (!condition) throw new Exception($”Failed: {msg}”); } Guard(user.Age > 18); // Throws: “Failed: user.Age > 18”

Read More
C#

C#: Why You Should ‘Seal’ Your Classes for Performance

- 28.02.26 - ErcanOPAK comment on C#: Why You Should ‘Seal’ Your Classes for Performance

If you don’t expect a class to be inherited, use the sealed keyword. The Science: The JIT compiler can perform ‘Devirtualization’ on sealed classes. Since it knows there are no overrides, it calls methods directly instead of looking up the virtual method table (vtable). Small gains in many places lead to a much faster system.

Read More
C#

C#: Save Memory with ValueTask in High-Throughput Scenarios

- 21.02.26 - ErcanOPAK comment on C#: Save Memory with ValueTask in High-Throughput Scenarios

If your async method often returns synchronously (like from a cache), using ValueTask instead of Task prevents an unnecessary object allocation on the heap.

Read More
C#

C#: Use Source Generators to Generate Boilerplate Code at Compile Time

- 03.02.26 - ErcanOPAK comment on C#: Use Source Generators to Generate Boilerplate Code at Compile Time

Writing repetitive mapping code, serialization logic, or validators? Source Generators create code at compile time, eliminating runtime reflection overhead. What Are Source Generators: // You write this: [GenerateToString] public partial class Person { public string Name { get; set; } public int Age { get; set; } } // Source Generator automatically creates this at […]

Read More
C#

C# Pattern Matching: Replace Complex If-Else Chains with Switch Expressions

- 01.02.26 - ErcanOPAK comment on C# Pattern Matching: Replace Complex If-Else Chains with Switch Expressions

Nested if-else statements making your code unreadable? C# 9+ switch expressions with pattern matching can reduce 50+ lines to 10. The Old Nightmare: public decimal CalculateDiscount(Customer customer, Order order) { if (customer == null) return 0; if (customer.IsPremium) { if (order.Total > 1000) return order.Total * 0.20m; else if (order.Total > 500) return order.Total * […]

Read More
November 2026
M T W T F S S
 1
2345678
9101112131415
16171819202122
23242526272829
30  
« Oct    

Most Viewed Posts

  • How to make theater mode the default for Youtube (1,055)
  • Get the User Name and Domain Name from an Email Address in SQL (981)
  • How to add default value for Entity Framework migrations for DateTime and Bool (977)
  • Get the First and Last Word from a String or Sentence in SQL (858)
  • How to select distinct rows in a datatable in C# (854)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (653)
  • Add Constraint to SQL Table to ensure email contains @ (609)
  • Average of all values in a column that are not zero in SQL (570)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (547)
  • Find numbers with more than two decimal places in SQL (475)

Recent Posts

  • C#: Fix a ConditionalWeakTable Entry Vanishing Too Soon
  • Docker: Fix a Stale COPY Layer After Editing .dockerignore
  • Photoshop: Fix a Pattern Overlay Scaling Wrong on a High-DPI File
  • SQL Server: Fix a Computed Column Index Skipped by Implicit Cast
  • HTML5: Fix a required Input Inside a Hidden Tab Blocking Submit
  • SQL Server: Fix ROW_NUMBER Ties Reordering Between Identical Runs
  • C#: Fix an Enum HasFlag Returning True for the Zero Value
  • WordPress: Fix Featured Images Vanishing After a CDN Migration
  • Photoshop: Fix Content-Aware Fill Smearing a Repeating Pattern
  • Asp.Net Core: Fix Antiforgery Tokens Rejected Behind a Reverse Proxy

Most Viewed Posts

  • How to make theater mode the default for Youtube (1,055)
  • Get the User Name and Domain Name from an Email Address in SQL (981)
  • How to add default value for Entity Framework migrations for DateTime and Bool (977)
  • Get the First and Last Word from a String or Sentence in SQL (858)
  • How to select distinct rows in a datatable in C# (854)

Recent Posts

  • C#: Fix a ConditionalWeakTable Entry Vanishing Too Soon
  • Docker: Fix a Stale COPY Layer After Editing .dockerignore
  • Photoshop: Fix a Pattern Overlay Scaling Wrong on a High-DPI File
  • SQL Server: Fix a Computed Column Index Skipped by Implicit Cast
  • HTML5: Fix a required Input Inside a Hidden Tab Blocking Submit

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com