Skip to content

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

Category: C#

C#

C# String Concatenation in Loops

- 21.01.26 - ErcanOPAK comment on C# String Concatenation in Loops

Simple loop, big cost. Why it happensImmutable strings. Why it mattersMemory churn. Smart fixUse StringBuilder. var sb = new StringBuilder();  

Read More
C#

C# Exceptions Used for Flow Control

- 21.01.26 - ErcanOPAK comment on C# Exceptions Used for Flow Control

Code “works”, performance suffers. Why it happensExceptions are expensive. Why it mattersHidden CPU cost. Smart fixUse conditional checks instead.

Read More
C#

C# LINQ Looks Clean but Runs Slow

- 21.01.26 - ErcanOPAK comment on C# LINQ Looks Clean but Runs Slow

Elegant code, heavy cost. Why it happensDeferred execution over large collections. Why it mattersHidden performance traps. Smart fixMaterialize results when reused. var list = query.ToList();  

Read More
Asp.Net Core / C#

ASP.NET Core Startup Is Slow

- 21.01.26 - ErcanOPAK comment on ASP.NET Core Startup Is Slow

Cold start hurts APIs. Why it happensHeavy dependency injection setup. Why it mattersFirst-request latency. Smart fixLazy-load expensive services. Lazy<MyService>  

Read More
C#

C# Value Types Copied More Than You Think

- 18.01.26 - ErcanOPAK comment on C# Value Types Copied More Than You Think

Structs feel lightweight. WhyPassed by value. TipUse in keyword. void Process(in MyStruct s) {}  

Read More
C#

C# Async Void Is Dangerous

- 18.01.26 - ErcanOPAK comment on C# Async Void Is Dangerous

Looks async, hides errors. WhyExceptions cannot be awaited. TipAvoid async void.

Read More
C#

C# Foreach vs For Performance Difference

- 18.01.26 - ErcanOPAK comment on C# Foreach vs For Performance Difference

Looks same, runs different. WhyEnumerator allocations. TipUse for in hot paths. for (int i = 0; i < list.Count; i++) {}  

Read More
Asp.Net Core / C#

.NET Core APIs Feel Slow Under Load

- 18.01.26 - ErcanOPAK comment on .NET Core APIs Feel Slow Under Load

Low traffic, bad response. WhySynchronous IO usage. TipPrefer async methods. await stream.ReadAsync(buffer);  

Read More
C#

C# String Operations Hurt Performance

- 16.01.26 - ErcanOPAK comment on C# String Operations Hurt Performance

Heavy string manipulation. WhyImmutable strings. TipUse StringBuilder in loops. var sb = new StringBuilder();  

Read More
C#

C# DateTime Bugs Appear Across Servers

- 16.01.26 - ErcanOPAK comment on C# DateTime Bugs Appear Across Servers

Same code, different results. WhyLocal time assumptions. TipAlways use UTC internally.

Read More
C#

C# LINQ Queries Allocate Too Much

- 16.01.26 - ErcanOPAK comment on C# LINQ Queries Allocate Too Much

Elegant but costly. WhyDeferred execution misunderstood. TipMaterialize once when reused. var data = query.ToList();  

Read More
C#

C# Collections Resize Too Often

- 15.01.26 - ErcanOPAK comment on C# Collections Resize Too Often

No errors, wasted cycles. WhyDefault capacity assumptions. TipInitialize collections with expected size. var list = new List<int>(capacity);  

Read More
C#

C# Exceptions Used for Control Flow

- 15.01.26 - ErcanOPAK comment on C# Exceptions Used for Control Flow

Works, but costs performance. WhyExceptions are expensive. TipUse conditionals for expected paths.

Read More
C#

C# Async Code Causes Thread Pool Pressure

- 15.01.26 - ErcanOPAK comment on C# Async Code Causes Thread Pool Pressure

Async everywhere, still bottlenecks. WhyCPU-bound work mixed with async I/O. TipIsolate CPU-heavy tasks.

Read More
C#

C# Collections Hurt Performance in Hot Paths

- 14.01.26 - ErcanOPAK comment on C# Collections Hurt Performance in Hot Paths

Correct code, slow execution. WhyUnnecessary allocations. TipReuse collections when possible.

Read More
C#

C# Async Code Hides Blocking Calls

- 14.01.26 - ErcanOPAK comment on C# Async Code Hides Blocking Calls

Looks async, behaves sync. WhyBlocking APIs inside async flows. await Task.Delay(1); // not Thread.Sleep  

Read More
C#

C# Objects Live Longer Than Expected

- 14.01.26 - ErcanOPAK comment on C# Objects Live Longer Than Expected

Memory grows slowly. WhyStatic references prevent GC. TipAvoid static state for request-based data.

Read More
C#

C# LINQ Is Not Free

- 13.01.26 - ErcanOPAK comment on C# LINQ Is Not Free

Readable code hides allocations. WhyEnumerators and deferred execution. Tip Use LINQ for clarity, loops for hot paths.

Read More
C#

C# Structs Hurt Performance When Misused

- 13.01.26 - ErcanOPAK comment on C# Structs Hurt Performance When Misused

Structs feel fast, sometimes aren’t. WhyLarge structs copy frequently. Tip Use structs only for small, immutable data.

Read More
C#

C# Async Code Still Causes High CPU

- 13.01.26 - ErcanOPAK comment on C# Async Code Still Causes High CPU

Async everywhere, still heavy. WhyCPU-bound work inside async flows. Tip Separate CPU-bound and I/O-bound tasks.

Read More
C#

C# Logging Produces Too Much Noise

- 12.01.26 - ErcanOPAK comment on C# Logging Produces Too Much Noise

Logs exist, signal lost. WhyNo log level strategy. Tip Log intent, not execution.

Read More
C#

C# Dependency Injection Containers Slow Startup

- 12.01.26 - ErcanOPAK comment on C# Dependency Injection Containers Slow Startup

Large apps feel heavy. WhyOver-registration and reflection. Tip Avoid unnecessary service lifetimes.

Read More
C#

C# Records Used Where Classes Fit Better

- 12.01.26 - ErcanOPAK comment on C# Records Used Where Classes Fit Better

Looks modern, causes issues. WhyRecords emphasize immutability and value semantics. Tip Use records intentionally, not everywhere.

Read More
C#

C# LINQ Looks Clean but Allocates Heavily

- 11.01.26 - ErcanOPAK comment on C# LINQ Looks Clean but Allocates Heavily

Readable code, hidden cost. WhyDeferred execution and allocations. Fix Use loops for hot paths.

Read More
C#

C# Value Types Cause Hidden Copies

- 11.01.26 - ErcanOPAK comment on C# Value Types Cause Hidden Copies

Structs feel fast… sometimes aren’t. WhyLarge structs are copied frequently. Fix Pass large structs by in reference.

Read More
C#

C# Async Code Still Blocks Threads

- 11.01.26 - ErcanOPAK comment on C# Async Code Still Blocks Threads

Async keyword isn’t magic. WhyBlocking calls inside async flows. Fix Never mix Task.Run with blocking I/O.

Read More
C#

C# Exceptions Used as Flow Control

- 07.01.26 - ErcanOPAK comment on C# Exceptions Used as Flow Control

Code works… but crawls. WhyExceptions are expensive. Fix Use conditional logic for expected paths.

Read More
C#

C# String Concatenation Hurts Performance in Loops

- 07.01.26 - ErcanOPAK comment on C# String Concatenation Hurts Performance in Loops

Looks harmless, isn’t. WhyImmutable strings cause repeated allocations. Fix Use StringBuilder for iterative builds.

Read More
C#

C# lock Statements Reduce Scalability

- 07.01.26 - ErcanOPAK comment on C# lock Statements Reduce Scalability

Code is safe but slow. WhyThreads block instead of cooperating. Fix Prefer concurrent collections when possible.

Read More
C#

C# Static Constructors Break Startup

- 06.01.26 - ErcanOPAK comment on C# Static Constructors Break Startup

App fails before logging. WhyExceptions thrown too early. FixMove logic out of static constructors.

Read More
Page 6 of 14
« Previous 1 2 3 4 5 6 7 8 9 10 11 … 14 Next »

Posts navigation

Older posts
Newer posts
April 2026
M T W T F S S
 12345
6789101112
13141516171819
20212223242526
27282930  
« Mar    

Most Viewed Posts

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

Recent Posts

  • C#: Use Init-Only Setters for Immutable Objects After Construction
  • C#: Use Expression-Bodied Members for Concise Single-Line Methods
  • C#: Enable Nullable Reference Types to Eliminate Null Reference Exceptions
  • C#: Use Record Types for Immutable Data Objects
  • SQL: Use CTEs for Readable Complex Queries
  • SQL: Use Window Functions for Advanced Analytical Queries
  • .NET Core: Use Background Services for Long-Running Tasks
  • .NET Core: Use Minimal APIs for Lightweight HTTP Services
  • Git: Use Cherry-Pick to Apply Specific Commits Across Branches
  • Git: Use Interactive Rebase to Clean Up Commit History Before Merge

Most Viewed Posts

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

Recent Posts

  • C#: Use Init-Only Setters for Immutable Objects After Construction
  • C#: Use Expression-Bodied Members for Concise Single-Line Methods
  • C#: Enable Nullable Reference Types to Eliminate Null Reference Exceptions
  • C#: Use Record Types for Immutable Data Objects
  • SQL: Use CTEs for Readable Complex Queries

Social

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