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

Month: June 2026

C#

C#: Use String Interpolation Instead of Concatenation

- 07.06.26 - ErcanOPAK comment on C#: Use String Interpolation Instead of Concatenation

๐Ÿ”ค $”Hello {name}” is Magic String concatenation is messy. String interpolation ($”) embeds variables directly. More readable, fewer bugs. โŒ Concatenation string message = “Hello, ” + name + “! You are ” + age + ” years old.”; string sql = “SELECT * FROM users WHERE id = ” + userId; string html = […]

Read More
C#

C#: Use Tuples to Return Multiple Values from Methods

- 07.06.26 - ErcanOPAK comment on C#: Use Tuples to Return Multiple Values from Methods

๐Ÿ“ฆ out parameters are clunky. Tuples are elegant. Need to return multiple values? Tuples return multiple values without creating a class. Named fields, deconstruction, lightweight. โŒ Out Parameters public void GetUser(int id, out string name, out int age) { name = “Alice”; age = 30; } // Usage GetUser(1, out var name, out var age); […]

Read More
SQL

SQL: Use ISNULL and NULLIF for Smart NULL Handling

- 07.06.26 - ErcanOPAK comment on SQL: Use ISNULL and NULLIF for Smart NULL Handling

๐Ÿ”„ Replace NULL with Default, or Replace Value with NULL ISNULL replaces NULL with default. NULLIF replaces value with NULL. Perfect for data cleaning, division by zero, optional fields. ๐Ÿ“ ISNULL (SQL Server) / IFNULL (MySQL) / COALESCE (Portable) — SQL Server SELECT ISNULL(phone, ‘No phone’) as contact FROM users; — MySQL SELECT IFNULL(phone, ‘No […]

Read More
Asp.Net Core

.NET Core: Use Data Annotations for Model Validation

- 07.06.26 - ErcanOPAK comment on .NET Core: Use Data Annotations for Model Validation

โœ… Validate Models with Attributes, Not If Statements Manual validation is tedious. Data Annotations validate automatically. Clean models, automatic error messages. ๐Ÿ“ Common Attributes public class User { [Required(ErrorMessage = “Name is required”)] [StringLength(100, MinimumLength = 2)] public string Name { get; set; } [Required] [EmailAddress] public string Email { get; set; } [Range(18, 99)] […]

Read More
Git

Git: Use Git Clean to Remove Untracked Files

- 07.06.26 - ErcanOPAK comment on Git: Use Git Clean to Remove Untracked Files

๐Ÿ—‘๏ธ Delete Temporary Files Cluttering Your Workspace Build artifacts, logs, temp files โ€” not in .gitignore yet. git clean removes untracked files. Clean workspace, fresh start. ๐Ÿ“ Basic Clean # Preview what would be deleted (dry run) git clean -n # Delete untracked files (not folders) git clean -f # Delete untracked files and folders […]

Read More
Ajax

Ajax: Add Custom Headers to Fetch Requests

- 07.06.26 - ErcanOPAK comment on Ajax: Add Custom Headers to Fetch Requests

๐Ÿ“‹ API Keys, Auth Tokens, Custom Headers Some APIs require custom headers. Headers option in fetch adds them. Authentication, content type, custom metadata. ๐Ÿ“ Adding Headers // Basic headers const response = await fetch(‘/api/data’, { headers: { ‘Content-Type’: ‘application/json’, ‘Accept’: ‘application/json’ } }); // Authentication token const token = ‘your-jwt-token’; await fetch(‘/api/protected’, { headers: { […]

Read More
JavaScript

JavaScript: Use console.table to Display Arrays as Tables

- 07.06.26 - ErcanOPAK comment on JavaScript: Use console.table to Display Arrays as Tables

๐Ÿ“Š console.log() is Messy for Arrays Array of objects logs as expandable tree. console.table() displays as formatted table. Much easier to read. ๐Ÿ“ Basic Usage const users = [ { id: 1, name: ‘Alice’, email: ‘alice@example.com’ }, { id: 2, name: ‘Bob’, email: ‘bob@example.com’ }, { id: 3, name: ‘Charlie’, email: ‘charlie@example.com’ } ]; console.table(users); […]

Read More
HTML

HTML: Use Spellcheck Attribute to Enable Browser Spell Check

- 07.06.26 - ErcanOPAK comment on HTML: Use Spellcheck Attribute to Enable Browser Spell Check

โœ๏ธ Red Squiggly Lines in Your Textarea Textareas don’t spell-check by default. spellcheck attribute enables browser spell checking. Better user-generated content. ๐Ÿ“ Basic Usage <!– Enable spell check –> <textarea spellcheck=”true” rows=”5″ cols=”50″></textarea> <input type=”text” spellcheck=”true”> <!– Disable spell check –> <input type=”text” spellcheck=”false”> <!– For code editors (disable spell check) –> <textarea class=”code-editor” spellcheck=”false”>function […]

Read More
CSS

CSS: Use user-select to Prevent Text Selection

- 07.06.26 - ErcanOPAK comment on CSS: Use user-select to Prevent Text Selection

๐Ÿšซ Stop Users from Selecting UI Elements Double-clicking button selects text. Dragging mouse selects UI labels. user-select prevents accidental selection. Better UX. ๐Ÿ“ Basic Usage /* Prevent selection on entire app */ body { user-select: none; } /* Allow selection on specific elements */ .content { user-select: text; } /* Buttons and UI elements */ […]

Read More
Windows

Windows 11: Use Snipping Tool for Instant Screenshots

- 07.06.26 - ErcanOPAK comment on Windows 11: Use Snipping Tool for Instant Screenshots

๐Ÿ“ธ Win + Shift + S = Best Screenshot Shortcut Print Screen captures entire screen. Win + Shift + S opens snipping toolbar. Select area, copy to clipboard, paste anywhere. ๐Ÿ“ Modes Win + Shift + S Toolbar options: – Rectangular snip (default) – Freeform snip (draw custom shape) – Window snip (capture specific window) […]

Read More
AI

AI Prompt: Generate Recipes from Ingredients You Have

- 07.06.26 - ErcanOPAK comment on AI Prompt: Generate Recipes from Ingredients You Have

๐Ÿณ “What can I cook with chicken, rice, and bell peppers?” Don’t know what to cook with ingredients on hand? AI generates recipes from your ingredients. No more food waste. ๐Ÿ“ The Prompt I have these ingredients: [list your ingredients here] I also have basic pantry items: salt, pepper, oil, butter, flour, sugar, eggs, milk. […]

Read More
Docker

Docker: Use Docker Commit to Save Container State as Image

- 07.06.26 - ErcanOPAK comment on Docker: Use Docker Commit to Save Container State as Image

๐Ÿ’พ Made Changes Inside Container? Save Them! You debugged inside container. Installed packages. Now you want to save it. docker commit creates image from running container. ๐Ÿ“ Basic Commit # Start container docker run -it ubuntu bash # Inside container: install packages apt-get update apt-get install -y nginx # Exit (Ctrl+D or exit) # Commit […]

Read More
Kubernetes

Kubernetes: Use Namespaces to Organize Your Cluster

- 07.06.26 - ErcanOPAK comment on Kubernetes: Use Namespaces to Organize Your Cluster

๐Ÿ“ Virtual Clusters Inside One Physical Cluster All pods in default namespace? Chaos. Namespaces separate environments, teams, or components. Resource quotas, RBAC per namespace. ๐Ÿ“ Create and Use Namespaces # Create namespace kubectl create namespace development kubectl create namespace staging kubectl create namespace production # List namespaces kubectl get namespaces # Run pod in specific […]

Read More
Wordpress

WordPress: Understand User Roles and Capabilities for Better Security

- 07.06.26 - ErcanOPAK comment on WordPress: Understand User Roles and Capabilities for Better Security

๐Ÿ‘ฅ Never Give Admin to Everyone Admin has all powers. User roles limit access. Editor writes, Author edits own, Subscriber reads only. Least privilege principle. ๐Ÿ“ Default Roles Administrator: – Full control over site – Add/delete users, install plugins, edit themes – Risk: Can break everything Editor: – Publish and manage all posts/pages – Moderate […]

Read More
Photoshop

Photoshop: Use Match Color to Unify Colors Across Photos

- 07.06.26 - ErcanOPAK comment on Photoshop: Use Match Color to Unify Colors Across Photos

๐ŸŽจ Make All Your Photos Look Like They Were Shot Together Different lighting, different cameras. Match Color transfers color palette from one image to another. Perfect for photo series, product shots. ๐Ÿ“ How to Use 1. Open source image (with desired colors) 2. Open target image (to be adjusted) 3. Select target image 4. Image […]

Read More
Visual Studio

Visual Studio: Sync Settings Across Multiple Computers

- 07.06.26 - ErcanOPAK comment on Visual Studio: Sync Settings Across Multiple Computers

โ˜๏ธ Your VS Settings Everywhere Theme, keyboard shortcuts, extensions โ€” setting up a new PC takes hours. VS Settings Sync roams everything. Sign in, done. ๐Ÿ”ง Enable Sync 1. File โ†’ Account Settings 2. Sign in with Microsoft account 3. Tools โ†’ Options โ†’ Environment โ†’ Accounts 4. Check “Synchronize settings across devices” What syncs: […]

Read More
C#

C#: Use Switch Expressions Instead of Switch Statements

- 07.06.26 - ErcanOPAK comment on C#: Use Switch Expressions Instead of Switch Statements

โžก๏ธ switch expression is an expression, not a statement Switch statements are verbose. Switch expressions return values. Less code, fewer bugs, no fall-through. โŒ Switch Statement string GetGrade(int score) { string grade; switch (score) { case >= 90: grade = “A”; break; case >= 80: grade = “B”; break; default: grade = “F”; break; } […]

Read More
C#

C#: Use ^ and .. for Indexing from End and Ranges

- 07.06.26 - ErcanOPAK comment on C#: Use ^ and .. for Indexing from End and Ranges

๐Ÿ“ arr[^1] is Last Element. arr[1..3] is Range. arr[arr.Length – 1] is verbose. ^ operator indexes from end. .. operator creates ranges. Python-like slicing in C#. โŒ Old Way var last = arr[arr.Length – 1]; var secondLast = arr[arr.Length – 2]; var slice = arr.Skip(1).Take(3).ToArray(); โœ… Index and Range var last = arr[^1]; var secondLast […]

Read More
SQL

SQL: Use COALESCE for First Non-Null Value

- 07.06.26 - ErcanOPAK comment on SQL: Use COALESCE for First Non-Null Value

๐Ÿ“‹ COALESCE is NVL2, ISNULL, and IFNULL Combined Need first non-null value? COALESCE takes multiple arguments, returns first non-null. Works across all databases. ๐Ÿ“ Basic COALESCE — Return first non-null SELECT COALESCE(null, null, ‘first’, ‘second’); — Returns ‘first’ SELECT COALESCE(phone, mobile, email, ‘No contact’); — Returns phone if not null, else mobile, else email, else […]

Read More
Asp.Net Core

.NET Core: Enable Response Compression for Smaller Payloads

- 07.06.26 - ErcanOPAK comment on .NET Core: Enable Response Compression for Smaller Payloads

โšก 70% Smaller Responses, Same Content JSON responses are text. Text compresses well. Response compression GZIPs responses automatically. Faster downloads, less bandwidth. ๐Ÿ“ Enable Compression // Program.cs builder.Services.AddResponseCompression(options => { options.EnableForHttps = true; options.Providers.Add(); options.Providers.Add(); options.MimeTypes = ResponseCompressionDefaults.MimeTypes.Concat( new[] { “application/json”, “text/plain” } ); }); builder.Services.Configure(options => { options.Level = CompressionLevel.Optimal; // Fastest, Optimal, NoCompression […]

Read More
Git

Git: Use Cherry-Pick to Apply Specific Commits to Another Branch

- 07.06.26 - ErcanOPAK comment on Git: Use Cherry-Pick to Apply Specific Commits to Another Branch

๐Ÿ’ Need One Commit from Another Branch? Merge brings all commits. Sometimes you need just one. Cherry-pick applies specific commits to current branch. ๐Ÿ“ Basic Cherry-Pick # Switch to target branch git checkout main # Cherry-pick a commit from feature branch git cherry-pick a1b2c3d # Cherry-pick multiple commits git cherry-pick a1b2c3d d4e5f6g g7h8i9j # Cherry-pick […]

Read More
Ajax

Ajax: Handle Binary Responses (Images, PDFs, ZIPs) with Blob

- 07.06.26 - ErcanOPAK comment on Ajax: Handle Binary Responses (Images, PDFs, ZIPs) with Blob

๐Ÿ“„ Download Files via AJAX Fetch JSON is common. What about images? PDFs? ZIPs? Blob responses handle binary data. Create download links dynamically. ๐Ÿ“ Download Image async function downloadImage(url) { const response = await fetch(url); const blob = await response.blob(); const imageUrl = URL.createObjectURL(blob); const img = document.createElement(‘img’); img.src = imageUrl; document.body.appendChild(img); // Clean up […]

Read More
JavaScript

JavaScript: Use ?? Instead of || for Default Values

- 07.06.26 - ErcanOPAK comment on JavaScript: Use ?? Instead of || for Default Values

|| treats 0, ”, false as falsy. ?? only checks null/undefined. Default values with || break when value is 0. Nullish coalescing (??) fixes this. Use ?? for default values. โŒ || (Bug with 0) const volume = userVolume || 50; // If userVolume = 0 โ†’ volume = 50 (WRONG!) const name = userName […]

Read More
HTML

HTML: Use Autofocus Attribute to Focus Input on Page Load

- 07.06.26 - ErcanOPAK comment on HTML: Use Autofocus Attribute to Focus Input on Page Load

โŒจ๏ธ User Can Type Immediately Search page? Login form? User must click input first. autofocus selects input automatically. One less click. ๐Ÿ“ Basic Usage <!– Search page –> <input type=”search” name=”q” autofocus placeholder=”Search…” “> <!– Login page –> <input type=”email” name=”email” autofocus placeholder=”Email”> <!– Modal dialog –> <input type=”text” name=”name” autofocus> <!– Works on any […]

Read More
CSS

CSS: Use scroll-behavior: smooth for Smooth Page Navigation

- 07.06.26 - ErcanOPAK comment on CSS: Use scroll-behavior: smooth for Smooth Page Navigation

๐Ÿ“œ Instant Jump is Jarring. Smooth is Better. Anchor links jump instantly. scroll-behavior: smooth animates scrolling. Better UX, no JavaScript. ๐Ÿ“ Basic Usage /* Apply to entire page */ html { scroll-behavior: smooth; } /* Apply only to specific container */ .scroll-container { scroll-behavior: smooth; overflow-y: auto; height: 400px; } /* HTML structure */ <a […]

Read More
Windows

Windows 11: Press Win + . to Insert Emojis, GIFs, and Symbols Anywhere

- 07.06.26 - ErcanOPAK comment on Windows 11: Press Win + . to Insert Emojis, GIFs, and Symbols Anywhere

๐Ÿ˜Š Emojis, Kaomoji, Symbols, GIFs โ€” One Shortcut Need a copyright symbol? An emoji? A GIF? Win + . (period) opens emoji panel everywhere. Browsers, documents, code editors. ๐Ÿ“ What’s Inside Win + . or Win + ; Tabs: – ๐Ÿ˜Š Emojis (smileys, people, animals, food, activities) – ๐Ÿ€† Kaomoji (Japanese text emoticons) (โ—•โ€ฟโ—•) – […]

Read More
AI

AI Prompt: Write Professional Emails from Bullet Points

- 07.06.26 - ErcanOPAK comment on AI Prompt: Write Professional Emails from Bullet Points

โœ‰๏ธ Turn Bullet Points into Professional Emails Don’t know how to phrase that email? AI writes professional emails from your bullet points. Different tones, styles, lengths. ๐Ÿ“ The Prompt Write a professional email with these key points: [Subject]: [email subject] Key points to cover: – [Point 1] – [Point 2] – [Point 3] Recipient: [Colleague […]

Read More
Docker

Docker: Never Write Logs to Files Inside Containers

- 07.06.26 - ErcanOPAK comment on Docker: Never Write Logs to Files Inside Containers

๐Ÿ“ Log to stdout/stderr, Not Files Log files inside container fill disk. Container restarts lose logs. Docker captures stdout/stderr. Use docker logs. โœ… Good vs Bad // โŒ BAD: Writing to file File.WriteAllText(“/app/logs/app.log”, message); // โœ… GOOD: Console output Console.WriteLine(message); // โŒ BAD: Log4Net to file // โœ… GOOD: Serilog to Console // Docker command […]

Read More
Kubernetes

Kubernetes: Always Set CPU and Memory Requests and Limits

- 07.06.26 - ErcanOPAK comment on Kubernetes: Always Set CPU and Memory Requests and Limits

โš™๏ธ No Requests = Unpredictable Scheduling Without resource requests, pods can starve others. Requests and limits ensure fair sharing and prevent resource exhaustion. ๐Ÿ“ Setting Resources apiVersion: v1 kind: Pod metadata: name: myapp spec: containers: – name: app image: myapp:latest resources: requests: memory: “256Mi” cpu: “250m” limits: memory: “512Mi” cpu: “500m” # CPU units: 1000m […]

Read More
Wordpress

WordPress: Use RSS Feeds to Display Content on Other Sites

- 07.06.26 - ErcanOPAK comment on WordPress: Use RSS Feeds to Display Content on Other Sites

๐Ÿ“ก WordPress has Built-in RSS Feeds for Everything Display posts on other sites, newsletters, or mobile apps. WordPress RSS feeds are ready to use. No plugins needed. ๐Ÿ“ Feed URLs # Main feed (latest 10 posts) https://yoursite.com/feed/ # Category feed https://yoursite.com/category/news/feed/ # Tag feed https://yoursite.com/tag/wordpress/feed/ # Author feed https://yoursite.com/author/admin/feed/ # Search feed https://yoursite.com/?s=keyword&feed=rss2 # Comments […]

Read More
Page 1 of 4
1 2 3 4 Next ยป

Posts pagination

1 2 3 4 Next »
June 2026
M T W T F S S
1234567
891011121314
15161718192021
22232425262728
2930  
« May    

Most Viewed Posts

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

Recent Posts

  • C#: Use String Interpolation Instead of Concatenation
  • C#: Use Tuples to Return Multiple Values from Methods
  • SQL: Use ISNULL and NULLIF for Smart NULL Handling
  • .NET Core: Use Data Annotations for Model Validation
  • Git: Use Git Clean to Remove Untracked Files
  • Ajax: Add Custom Headers to Fetch Requests
  • JavaScript: Use console.table to Display Arrays as Tables
  • HTML: Use Spellcheck Attribute to Enable Browser Spell Check
  • CSS: Use user-select to Prevent Text Selection
  • Windows 11: Use Snipping Tool for Instant Screenshots

Most Viewed Posts

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

Recent Posts

  • C#: Use String Interpolation Instead of Concatenation
  • C#: Use Tuples to Return Multiple Values from Methods
  • SQL: Use ISNULL and NULLIF for Smart NULL Handling
  • .NET Core: Use Data Annotations for Model Validation
  • Git: Use Git Clean to Remove Untracked Files

Social

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