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: .NET 6

C#

C#: Use Throw Helpers for Concise Null Checks (.NET 6+)

- 30.05.26 - ErcanOPAK comment on C#: Use Throw Helpers for Concise Null Checks (.NET 6+)

๐ŸŽฏ One Line Null Check if (arg == null) throw new ArgumentNullException(nameof(arg)); is so 2019. Throw helpers do it in one line. Less code, fewer bugs. โŒ Old Way (4 lines) public void Process(string name, int? age) { if (name == null) throw new ArgumentNullException(nameof(name)); if (age == null) throw new ArgumentNullException(nameof(age)); // Logic here […]

Read More
C#

C#: Use DateOnly and TimeOnly When You Don’t Need DateTime

- 29.05.26 - ErcanOPAK comment on C#: Use DateOnly and TimeOnly When You Don’t Need DateTime

๐Ÿ“… Date Without Time. Time Without Date. Birthday has no time. Alarm has no date. DateOnly and TimeOnly prevent bugs from midnight times, time zones, and meaningless components. ๐Ÿ“ DateOnly Examples // Create DateOnly DateOnly birthday = new DateOnly(1990, 5, 15); DateOnly today = DateOnly.FromDateTime(DateTime.Today); // Parse DateOnly parsed = DateOnly.Parse(“2024-12-25”); // Operations DateOnly tomorrow […]

Read More
C#

C#: Use Global Usings and Implicit Usings to Clean Up Files

- 27.05.26 - ErcanOPAK comment on C#: Use Global Usings and Implicit Usings to Clean Up Files

๐Ÿงน Remove Using Statements Forever Every file starts with 10 using statements? Global usings define once for entire project. Implicit usings add common ones automatically. ๐Ÿ“ฆ GlobalUsings.cs File // GlobalUsings.cs global using System; global using System.Collections.Generic; global using System.Linq; global using System.Threading.Tasks; global using Microsoft.Extensions.Logging; global using MyApp.Common; // Global using with alias global using […]

Read More
Asp.Net Core

.NET Core: Use Minimal APIs for Lightweight HTTP Services

- 30.03.26 - ErcanOPAK comment on .NET Core: Use Minimal APIs for Lightweight HTTP Services

๐Ÿš€ APIs in 10 Lines of Code MVC Controllers for simple API? Overkill. Minimal APIs (.NET 6+) create HTTP endpoints with minimal ceremony. Perfect for microservices, simple APIs. Traditional Controller vs Minimal API // โŒ Traditional Controller (verbose) [ApiController] [Route(“api/[controller]”)] public class UsersController : ControllerBase { private readonly IUserService _userService; public UsersController(IUserService userService) { _userService […]

Read More
Asp.Net Core

.NET Core: Use Minimal APIs for Lightweight Endpoints

- 19.03.26 - ErcanOPAK comment on .NET Core: Use Minimal APIs for Lightweight Endpoints

โšก Build APIs in 5 Lines of Code Skip controllers, routing, Startup.cs. Minimal APIs (.NET 6+) make simple endpoints incredibly simple. Traditional Controller Way // Startup.cs public void ConfigureServices(IServiceCollection services) { services.AddControllers(); } public void Configure(IApplicationBuilder app) { app.UseRouting(); app.UseEndpoints(endpoints => endpoints.MapControllers()); } // UsersController.cs [ApiController] [Route(“api/[controller]”)] public class UsersController : ControllerBase { [HttpGet] public […]

Read More
Asp.Net Core

.NET Core: Use Global Using Directives to Avoid Repeating Imports

- 13.02.26 - ErcanOPAK comment on .NET Core: Use Global Using Directives to Avoid Repeating Imports

Typing the same using statements in every file? Declare them globally once. Create GlobalUsings.cs: // GlobalUsings.cs global using System; global using System.Collections.Generic; global using System.Linq; global using System.Threading.Tasks; global using Microsoft.EntityFrameworkCore; Now these namespaces are available in ALL files automatically! Your Other Files: // ProductService.cs // No using statements needed! public class ProductService { private […]

Read More
Asp.Net Core

.NET Core: Use File-Scoped Namespaces to Reduce Indentation

- 13.02.26 - ErcanOPAK comment on .NET Core: Use File-Scoped Namespaces to Reduce Indentation

Tired of extra indentation from namespace blocks? Use file-scoped namespaces. Old Way: namespace MyApp.Services { public class ProductService { public void DoSomething() { // Code here } } } // Everything indented one level New Way (.NET 6+): namespace MyApp.Services; public class ProductService { public void DoSomething() { // Code here – one less indent […]

Read More
Asp.Net Core

.NET Core: Use Top-Level Statements to Skip Program Class Boilerplate

- 13.02.26 - ErcanOPAK comment on .NET Core: Use Top-Level Statements to Skip Program Class Boilerplate

Don’t need Program class and Main method for simple apps. Write code directly. Old Way: namespace MyApp { class Program { static void Main(string[] args) { Console.WriteLine(“Hello World”); } } } New Way (.NET 6+): Console.WriteLine(“Hello World”); That’s your entire Program.cs file! Compiler generates the boilerplate. Can Still Use Services: var builder = WebApplication.CreateBuilder(args); var […]

Read More
Asp.Net Core

.NET Core Configuration Magic: How IOptions Pattern Solves Multi-Environment Headaches

- 05.02.26 - ErcanOPAK comment on .NET Core Configuration Magic: How IOptions Pattern Solves Multi-Environment Headaches

Tired of connection strings breaking between dev/test/prod? IOptions pattern with validation ensures your app never starts with wrong config. The Configuration Nightmare: // The old way – scattered magic strings public class OrderService { private readonly string _connectionString; public OrderService(IConfiguration configuration) { _connectionString = configuration.GetConnectionString(“DefaultConnection”); // What if configuration key doesn’t exist? // What if […]

Read More
Asp.Net Core

.NET Core: Use Minimal APIs to Create Lightweight Endpoints Without Controllers

- 03.02.26 - ErcanOPAK comment on .NET Core: Use Minimal APIs to Create Lightweight Endpoints Without Controllers

Creating a controller, action method, and routing just to return simple JSON? Minimal APIs in .NET 6+ let you define endpoints in 3 lines. Traditional Controller Way: [ApiController] [Route(“api/[controller]”)] public class ProductsController : ControllerBase { private readonly IProductService _productService; public ProductsController(IProductService productService) { _productService = productService; } [HttpGet] public async Task GetAll() { var products […]

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