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#

Applications / C# / Software

Prayer Times App v1.1.1

- 30.12.25 | 05.04.26 - ErcanOPAK comment on Prayer Times App v1.1.1

🕌 Modern, User-Friendly Prayer Times Application Completely free, portable prayer times application for Windows — no installation required. Supports 203 countries and 4,120+ cities worldwide. ✨ Features 🌍 Global Support: 203 countries, 4,120+ cities worldwide 🇹🇷 🇬🇧 Bilingual: Turkish and English interface đź“– Islamic Library: 28 surahs, 36 prayers, 40 hadiths (favorites & smart search) […]

Read More
C# / Uygulamalar / Yazılım

Namaz Vakitleri Uygulaması v1.1.1

- 30.12.25 | 05.04.26 - ErcanOPAK comment on Namaz Vakitleri Uygulaması v1.1.1

🕌 Modern, Kullanıcı Dostu Namaz Vakitleri Uygulaması Windows için tamamen ĂĽcretsiz, kurulum gerektirmeyen (portable) namaz vakitleri uygulaması. DĂĽnya genelinde 203 ĂĽlke ve 4,120+ Ĺźehri destekliyor. ✨ Ă–zellikler 🌍 KĂĽresel Destek: 203 ĂĽlke, 4,120+ Ĺźehir, TĂĽrkiye’nin tĂĽm il ve ilçeleri 🇹🇷 🇬🇧 Çift Dil: TĂĽrkçe ve İngilizce arayĂĽz đź“– İslami KĂĽtĂĽphane: 28 sure, 36 dua, 40 […]

Read More
C#

C# — List.ForEach() Is Slower Than foreach

- 29.12.25 - ErcanOPAK comment on C# — List.ForEach() Is Slower Than foreach

It allocates a delegate and blocks break/continue. âś… Prefer foreach (var item in list) { }  

Read More
C#

C# — DateTimeKind.Unspecified Breaks Serialization

- 29.12.25 - ErcanOPAK comment on C# — DateTimeKind.Unspecified Breaks Serialization

Unspecified kind leads to wrong conversions. âś… Rule Always specify: DateTime.SpecifyKind(date, DateTimeKind.Utc)  

Read More
C#

C# — record Types Can Accidentally Leak Data

- 29.12.25 - ErcanOPAK comment on C# — record Types Can Accidentally Leak Data

record auto-generates ToString(). public record User(string Email, string Password); ❌ Risk Sensitive data may appear in logs. ✅ Fix Override ToString() or avoid records for secrets.

Read More
Asp.Net Core / C#

Background Tasks the Right Way

- 29.12.25 - ErcanOPAK comment on Background Tasks the Right Way

The Problem: You are firing off Task.Run() in a controller and hoping it finishes, but the server kills it. The Fix: Implement BackgroundService. It’s the reliable, built-in way to run long-running processes. public class Worker : BackgroundService { protected override async Task ExecuteAsync(CancellationToken stoppingToken) { while (!stoppingToken.IsCancellationRequested) { // Your logic here await Task.Delay(1000, stoppingToken); […]

Read More
Asp.Net Core / C#

Hot Reload Configuration with IOptionsSnapshot

- 29.12.25 - ErcanOPAK comment on Hot Reload Configuration with IOptionsSnapshot

The Problem: You changed a value in appsettings.json, but the app keeps using the old value until you restart the server. The Fix: Inject IOptionsSnapshot<T> instead of IOptions<T>. It reads the config file every time the request is made. public class MyService { private readonly MySettings _settings; // Updates immediately when json changes! public MyService(IOptionsSnapshot<MySettings> […]

Read More
C#

Splitting Lists with .Chunk()

- 29.12.25 - ErcanOPAK comment on Splitting Lists with .Chunk()

The Problem: You need to process a list of 10,000 items in batches of 100, but writing the for loop math is tedious and error-prone. The Fix: Since .NET 6, you can simply use LINQ’s .Chunk(). var heavyItems = GetHugeList(); // Instantly splits into arrays of 100 items foreach (var batch in heavyItems.Chunk(100)) { ProcessBatch(batch); […]

Read More
C#

Stop Allocating Memory with Span

- 29.12.25 - ErcanOPAK comment on Stop Allocating Memory with Span

The Problem: You need to parse a large string (like a substring), but String.Substring() creates a new string object in memory every time, hurting performance. The Fix: Use Span<T>. It provides a type-safe, memory-safe representation of a contiguous region of arbitrary memory without allocation. string text = “2023-10-25”; // Instead of text.Substring(0, 4) which allocates… […]

Read More
C#

The Null Coalescing Assignment Operator (??=)

- 29.12.25 | 29.12.25 - ErcanOPAK comment on The Null Coalescing Assignment Operator (??=)

The Problem: You are writing verbose if (variable == null) checks just to assign a default value. The Fix: Use ??= to assign a variable only if it is currently null. It makes your initialization logic incredibly clean. // Old way if (myList == null) { myList = new List<string>(); } // Life-saver way myList […]

Read More
C#

C# — using Blocks Can Hide IO Bottlenecks

- 28.12.25 - ErcanOPAK comment on C# — using Blocks Can Hide IO Bottlenecks

using var stream = File.OpenRead(path); đź§  Problem Dispose can block while flushing buffers. âś… Rule Avoid heavy IO inside tight loops.

Read More
C#

C# — string.Concat Is Faster Than string.Format

- 28.12.25 - ErcanOPAK comment on C# — string.Concat Is Faster Than string.Format

Formatting is expensive. âś… Faster var s = string.Concat(a, “-“, b); ❌ Slower string.Format(“{0}-{1}”, a, b); Impact: hot paths, logging, serialization.  

Read More
C#

C# — readonly Fields Don’t Make Objects Immutable

- 28.12.25 - ErcanOPAK comment on C# — readonly Fields Don’t Make Objects Immutable

Many devs assume readonly = immutable. ❌ Reality readonly protects the reference, not the object. readonly List<int> items = new(); items.Add(1); // allowed ✅ Fix Use immutable collections when needed.

Read More
C#

Observability — Logs Without Correlation IDs Are Noise

- 28.12.25 - ErcanOPAK comment on Observability — Logs Without Correlation IDs Are Noise

Distributed tracing without IDs is guesswork. âś… Fix Propagate correlation IDs across services.

Read More
C#

JSON — Schema Validation Prevents Silent API Breakage

- 28.12.25 - ErcanOPAK comment on JSON — Schema Validation Prevents Silent API Breakage

Clients change. APIs break quietly. âś… Fix Validate JSON against schema before processing.

Read More
C#

Cancellation — Passing Token Is Not Enough

- 28.12.25 - ErcanOPAK comment on Cancellation — Passing Token Is Not Enough

You passed CancellationToken…but didn’t observe it. ✅ Rule Check ThrowIfCancellationRequested() in loops.

Read More
C#

Async Streams — IAsyncEnumerable Saves Memory

- 28.12.25 - ErcanOPAK comment on Async Streams — IAsyncEnumerable Saves Memory

Instead of loading everything: await foreach (var item in stream) Benefits Lower memory usage Faster first response Ideal for large datasets

Read More
C# / Entity Framework

EF Core — Change Tracking Is a Hidden Performance Tax

- 28.12.25 - ErcanOPAK comment on EF Core — Change Tracking Is a Hidden Performance Tax

Tracking thousands of entities slows everything. âś… Fix context.ChangeTracker.QueryTrackingBehavior = NoTracking; Or per query: .AsNoTracking()  

Read More
C#

Unicode — String Length Is Not What You Think

- 28.12.25 - ErcanOPAK comment on Unicode — String Length Is Not What You Think

“👨‍👩‍👧‍👦”.Length // NOT 1 Why UTF-16 code units Grapheme clusters âś… Fix Use text element enumeration for user-visible length.

Read More
C#

Time Zones — DateTime.Now Is a Data Corruption Bug

- 28.12.25 - ErcanOPAK comment on Time Zones — DateTime.Now Is a Data Corruption Bug

DateTime.Now depends on server locale. ❌ What breaks Distributed systems Daylight Saving Time Audits & reporting âś… Rule Store UTC, display local. DateTime.UtcNow  

Read More
Asp.Net Core / C#

.NET Core — Request Aborted Token Is Ignored Too Often

- 27.12.25 - ErcanOPAK comment on .NET Core — Request Aborted Token Is Ignored Too Often

Client disconnects — server keeps working. ✅ Fix Use: HttpContext.RequestAborted Cancel long-running operations immediately.

Read More
Asp.Net Core / C#

.NET Core — Async Controllers Can Still Block Threads

- 27.12.25 - ErcanOPAK comment on .NET Core — Async Controllers Can Still Block Threads

Async does NOT guarantee non-blocking. ❌ Hidden blocker Task.Result Task.Wait() ✅ Rule Async all the way — no sync-over-async.

Read More
C#

C# — Exceptions Are Extremely Expensive

- 27.12.25 - ErcanOPAK comment on C# — Exceptions Are Extremely Expensive

Exceptions are not control flow. ❌ Bad try { Parse(); } catch { } ✅ Better Use TryParse patterns. Impact Exceptions allocate Capture stack traces Kill throughput under load

Read More
C#

C# — foreach Copies Structs Silently

- 27.12.25 - ErcanOPAK comment on C# — foreach Copies Structs Silently

Iterating structs can create hidden copies. foreach (var item in largeStructList) { item.Modify(); // modifies a copy } âś… Fix Use ref foreach: foreach (ref var item in CollectionsMarshal.AsSpan(list))  

Read More
C#

C# — Memory Works with Async, Span Does Not

- 27.12.25 - ErcanOPAK comment on C# — Memory Works with Async, Span Does Not

Span<T> is stack-only.Once you await, the stack frame is gone. ❌ This breaks Span<byte> buffer = stackalloc byte[256]; await DoAsync(buffer); // 💥 ✅ Correct Memory<byte> buffer = new byte[256]; await DoAsync(buffer); Rule: Span<T> → sync, hot paths Memory<T> → async-safe

Read More
C#

C# — Async State Machines Increase Memory Usage

- 25.12.25 - ErcanOPAK comment on C# — Async State Machines Increase Memory Usage

Every async method allocates a state machine. đź§  Impact High-throughput services suffer Hot paths amplify cost âś… Optimization Use sync methods when no awaits are needed.

Read More
C#

C# — ConcurrentDictionary Is Not Always Faster

- 25.12.25 - ErcanOPAK comment on C# — ConcurrentDictionary Is Not Always Faster

Many devs replace Dictionary blindly. ❌ Reality Slower for low contention Higher memory usage Locks still exist internally ✅ Rule Use ConcurrentDictionary only under real concurrency.

Read More
C#

C# — Why readonly struct Can Be Slower Than class

- 25.12.25 - ErcanOPAK comment on C# — Why readonly struct Can Be Slower Than class

readonly struct looks like a performance win. ❌ Hidden cost Defensive copies are created when passed by value Happens silently in method calls âś… Fix Pass by in: void Process(in MyStruct value)  

Read More
Asp.Net Core / C#

.NET Core — Response Compression Isn’t Enabled by Default

- 21.12.25 - ErcanOPAK comment on .NET Core — Response Compression Isn’t Enabled by Default

Many APIs forget this. builder.Services.AddResponseCompression(); app.UseResponseCompression(); Result Smaller payloads Faster mobile clients Lower bandwidth costs

Read More
Asp.Net Core / C#

.NET Core — MapGroup() for API Versioning Without Pain

- 21.12.25 - ErcanOPAK comment on .NET Core — MapGroup() for API Versioning Without Pain

var v1 = app.MapGroup(“/api/v1”); v1.MapGet(“/users”, GetUsers); Benefits Cleaner routing Shared filters & auth Scales beautifully

Read More
Page 8 of 14
« Previous 1 … 3 4 5 6 7 8 9 10 11 12 13 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