<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Ravi Vishwakarma</title>
    <description>The latest articles on Forem by Ravi Vishwakarma (@ravivis13370227).</description>
    <link>https://forem.com/ravivis13370227</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F927623%2Fc560ed5b-5722-4b25-b9f7-36205b08c154.jpeg</url>
      <title>Forem: Ravi Vishwakarma</title>
      <link>https://forem.com/ravivis13370227</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/ravivis13370227"/>
    <language>en</language>
    <item>
      <title>EmailSpamChecker class for .NET Framework 4.7</title>
      <dc:creator>Ravi Vishwakarma</dc:creator>
      <pubDate>Wed, 18 Jun 2025 16:53:15 +0000</pubDate>
      <link>https://forem.com/ravivis13370227/emailspamchecker-class-for-net-framework-47-59h8</link>
      <guid>https://forem.com/ravivis13370227/emailspamchecker-class-for-net-framework-47-59h8</guid>
      <description>&lt;p&gt;Here’s a complete and reusable EmailSpamChecker class for .NET Framework 4.7, which performs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Syntax validation&lt;/li&gt;
&lt;li&gt;Blacklisted domain check&lt;/li&gt;
&lt;li&gt;MX record verification (requires DnsClient NuGet)&lt;/li&gt;
&lt;li&gt;Scoring logic for spam suspicion&lt;/li&gt;
&lt;li&gt;Customizable domain block list&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Step 1: Install DnsClient NuGet Package
&lt;/h3&gt;

&lt;p&gt;From NuGet Package Manager Console:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Install-Package DnsClient
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Step 2: EmailSpamChecker Class
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Mail;
using System.Text.RegularExpressions;
using DnsClient;

public class EmailSpamChecker
{
    private static readonly string[] _blacklistedDomains = new[]
    {
        "mailinator.com", "10minutemail.com", "guerrillamail.com",
        "tempmail.com", "desy.xyz", "yopmail.com", "trashmail.com"
    };

    private static readonly string[] _suspiciousTlds = new[]
    {
        ".xyz", ".tk", ".gq", ".ml", ".cf"
    };

    public class SpamCheckResult
    {
        public bool IsValid { get; set; }
        public int SpamScore { get; set; }
        public List&amp;lt;string&amp;gt; Issues { get; set; } = new List&amp;lt;string&amp;gt;();
    }

    public static SpamCheckResult CheckEmail(string email)
    {
        var result = new SpamCheckResult();

        // Check basic syntax
        if (!IsValidSyntax(email))
        {
            result.Issues.Add("Invalid email syntax.");
            result.SpamScore += 2;
            result.IsValid = false;
            return result;
        }

        string domain = email.Split('@')[1].ToLower();

        // Check blacklist
        if (_blacklistedDomains.Contains(domain))
        {
            result.Issues.Add("Domain is blacklisted.");
            result.SpamScore += 3;
        }

        // Check suspicious TLD
        if (_suspiciousTlds.Any(tld =&amp;gt; domain.EndsWith(tld)))
        {
            result.Issues.Add("Suspicious top-level domain.");
            result.SpamScore += 1;
        }

        // Check if it looks random (e.g., xas21@abc.xyz)
        if (IsRandomLooking(email))
        {
            result.Issues.Add("Username looks auto-generated or random.");
            result.SpamScore += 1;
        }

        // Check MX record
        if (!HasValidMxRecord(domain))
        {
            result.Issues.Add("Domain has no MX record (may not receive emails).");
            result.SpamScore += 2;
        }

        result.IsValid = result.SpamScore &amp;lt; 3;
        return result;
    }

    private static bool IsValidSyntax(string email)
    {
        try
        {
            var addr = new MailAddress(email);
            return addr.Address == email;
        }
        catch
        {
            return false;
        }
    }

    private static bool HasValidMxRecord(string domain)
    {
        try
        {
            var lookup = new LookupClient();
            var result = lookup.Query(domain, QueryType.MX);
            return result.Answers.MxRecords().Any();
        }
        catch
        {
            return false;
        }
    }

    private static bool IsRandomLooking(string email)
    {
        string user = email.Split('@')[0];

        // Count digits and special chars
        int digitCount = user.Count(char.IsDigit);
        int symbolCount = user.Count(c =&amp;gt; !char.IsLetterOrDigit(c));

        // Very short or too random
        return user.Length &amp;lt; 5 || digitCount + symbolCount &amp;gt; 4;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Usage Example
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string inputEmail = "xyz@desy.xyz";
var result = EmailSpamChecker.CheckEmail(inputEmail);

if (!result.IsValid)
{
    Console.WriteLine("Potential spam or invalid email:");
    foreach (var issue in result.Issues)
        Console.WriteLine($"- {issue}");
}
else
{
    Console.WriteLine("Email looks clean.");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Output Example
&lt;/h3&gt;

&lt;p&gt;Potential spam or invalid email:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Domain is blacklisted.&lt;/li&gt;
&lt;li&gt;Suspicious top-level domain.&lt;/li&gt;
&lt;li&gt;Domain has no MX record (may not receive emails).&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Thanks&lt;br&gt;
Keep Coding.&lt;/p&gt;

</description>
      <category>dotnet</category>
      <category>microsoft</category>
    </item>
    <item>
      <title>Clean Architecture in .net application step by step</title>
      <dc:creator>Ravi Vishwakarma</dc:creator>
      <pubDate>Sat, 12 Apr 2025 13:54:40 +0000</pubDate>
      <link>https://forem.com/ravivis13370227/clean-architecture-in-net-application-step-by-step-2ol0</link>
      <guid>https://forem.com/ravivis13370227/clean-architecture-in-net-application-step-by-step-2ol0</guid>
      <description>&lt;p&gt;&lt;strong&gt;Clean Architecture&lt;/strong&gt; is a software design philosophy introduced by &lt;strong&gt;Robert C. Martin (Uncle Bob)&lt;/strong&gt;. Its goal is to create systems that are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Independent of frameworks&lt;/li&gt;
&lt;li&gt;Testable&lt;/li&gt;
&lt;li&gt;Independent of UI or database&lt;/li&gt;
&lt;li&gt;Flexible and maintainable&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Key Principles
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Separation of Concerns&lt;/strong&gt;: Each layer of the application has a specific responsibility and doesn't mix with others.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dependency Rule&lt;/strong&gt;: Code dependencies must point inward, from outer layers (UI, DB) to inner layers (Use Cases, Entities). Inner layers know nothing about the outer layers.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Inversion of Control&lt;/strong&gt;: High-level policies (business rules) shouldn't depend on low-level details (DB, APIs). Instead, interfaces should be used to invert control.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Independence&lt;/strong&gt;: 

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Framework Independent&lt;/strong&gt;: Can change from ASP.NET to another without affecting core logic.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Database Independent&lt;/strong&gt;: Can switch from SQL Server to MongoDB.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;UI Independent&lt;/strong&gt;: Can change from Web to Mobile easily.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  The Layers
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Domain Layer (Entities)&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Contains core business rules&lt;/li&gt;
&lt;li&gt;Framework and UI agnostic&lt;/li&gt;
&lt;li&gt;Pure business objects (e.g., User, Order)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Application Layer (Use Cases)&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Contains application-specific logic&lt;/li&gt;
&lt;li&gt;Coordinates the flow of data&lt;/li&gt;
&lt;li&gt;Interfaces with repositories&lt;/li&gt;
&lt;li&gt;E.g., CreateUser, GetOrders&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Interface Adapters Layer&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Adapts data between use cases and frameworks&lt;/li&gt;
&lt;li&gt;Includes Controllers, Gateways, ViewModels&lt;/li&gt;
&lt;li&gt;Implements interfaces from Application Layer&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Frameworks &amp;amp; Drivers&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;External tools and frameworks (e.g., ASP.NET Core, EF Core)&lt;/li&gt;
&lt;li&gt;Dependency injection and infrastructure&lt;/li&gt;
&lt;li&gt;Least stable and most replaceable&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Flow of Control
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;UI (Controller) → Use Case → Domain Logic → Output/Result&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Controllers receive the input (e.g., HTTP request)&lt;/li&gt;
&lt;li&gt;Pass data to the Use Case&lt;/li&gt;
&lt;li&gt;Use Case performs business logic using the Domain&lt;/li&gt;
&lt;li&gt;Returns results (e.g., DTOs or ViewModels)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  ⚖️ Advantages
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;High Testability&lt;/strong&gt; – Business logic can be tested without UI or DB.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Easy to Maintain&lt;/strong&gt; – Changes in UI/DB won’t affect core logic.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scalability&lt;/strong&gt;– Modular design helps teams work independently.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Reusability&lt;/strong&gt;– Domain and Use Cases are reusable in different apps.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  ⚠️ Common Mistakes
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Violating the dependency rule (e.g., use case calling Entity Framework directly)&lt;/li&gt;
&lt;li&gt;Mixing business logic with framework code&lt;/li&gt;
&lt;li&gt;Skipping interfaces (tight coupling)&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🧱 Project Structure
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Solution&lt;/strong&gt;: CleanArchitectureDemo.sln&lt;br&gt;
&lt;strong&gt;Projects&lt;/strong&gt;:&lt;br&gt;
├── CleanArchitectureDemo.Domain         // &lt;strong&gt;Entities&lt;/strong&gt;&lt;br&gt;
├── CleanArchitectureDemo.Application    // &lt;strong&gt;Use Cases&lt;/strong&gt;&lt;br&gt;
├── CleanArchitectureDemo.Infrastructure // &lt;strong&gt;DB / Repositories&lt;/strong&gt;&lt;br&gt;
├── CleanArchitectureDemo.API            // &lt;strong&gt;Web API (Controllers)&lt;/strong&gt;&lt;/p&gt;


&lt;h2&gt;
  
  
  🔧 Create Projects
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dotnet new sln -n CleanArchitectureDemo

dotnet new classlib -n CleanArchitectureDemo.Domain
dotnet new classlib -n CleanArchitectureDemo.Application
dotnet new classlib -n CleanArchitectureDemo.Infrastructure
dotnet new webapi   -n CleanArchitectureDemo.API

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Add them to the solution:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dotnet sln add CleanArchitectureDemo.Domain
dotnet sln add CleanArchitectureDemo.Application
dotnet sln add CleanArchitectureDemo.Infrastructure
dotnet sln add CleanArchitectureDemo.API

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add project references:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dotnet add CleanArchitectureDemo.Application reference CleanArchitectureDemo.Domain
dotnet add CleanArchitectureDemo.Infrastructure reference CleanArchitectureDemo.Application
dotnet add CleanArchitectureDemo.API reference CleanArchitectureDemo.Application
dotnet add CleanArchitectureDemo.API reference CleanArchitectureDemo.Infrastructure

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  📁 Layer Implementations
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Domain/Entities/User.cs&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;namespace CleanArchitectureDemo.Domain.Entities
{
    public class User
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public string Email { get; set; }
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Application/Interfaces/IUserRepository.cs&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using CleanArchitectureDemo.Domain.Entities;
using System.Collections.Generic;

namespace CleanArchitectureDemo.Application.Interfaces
{
    public interface IUserRepository
    {
        IEnumerable&amp;lt;User&amp;gt; GetAll();
        User GetById(int id);
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. Application/UseCases/UserService.cs&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using CleanArchitectureDemo.Application.Interfaces;
using CleanArchitectureDemo.Domain.Entities;
using System.Collections.Generic;

namespace CleanArchitectureDemo.Application.UseCases
{
    public class UserService
    {
        private readonly IUserRepository _userRepository;

        public UserService(IUserRepository userRepository)
        {
            _userRepository = userRepository;
        }

        public IEnumerable&amp;lt;User&amp;gt; GetUsers() =&amp;gt; _userRepository.GetAll();

        public User GetUser(int id) =&amp;gt; _userRepository.GetById(id);
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4. Infrastructure/Repositories/InMemoryUserRepository.cs&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using CleanArchitectureDemo.Application.Interfaces;
using CleanArchitectureDemo.Domain.Entities;
using System.Collections.Generic;
using System.Linq;

namespace CleanArchitectureDemo.Infrastructure.Repositories
{
    public class InMemoryUserRepository : IUserRepository
    {
        private readonly List&amp;lt;User&amp;gt; _users = new()
        {
            new User { Id = 1, Name = "Alice", Email = "alice@example.com" },
            new User { Id = 2, Name = "Bob", Email = "bob@example.com" }
        };

        public IEnumerable&amp;lt;User&amp;gt; GetAll() =&amp;gt; _users;

        public User GetById(int id) =&amp;gt; _users.FirstOrDefault(u =&amp;gt; u.Id == id);
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;5. API/Controllers/UserController.cs&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using Microsoft.AspNetCore.Mvc;
using CleanArchitectureDemo.Application.UseCases;
using CleanArchitectureDemo.Domain.Entities;
using System.Collections.Generic;

namespace CleanArchitectureDemo.API.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class UserController : ControllerBase
    {
        private readonly UserService _userService;

        public UserController(UserService userService)
        {
            _userService = userService;
        }

        [HttpGet]
        public IEnumerable&amp;lt;User&amp;gt; Get() =&amp;gt; _userService.GetUsers();

        [HttpGet("{id}")]
        public ActionResult&amp;lt;User&amp;gt; Get(int id)
        {
            var user = _userService.GetUser(id);
            if (user == null)
                return NotFound();
            return user;
        }
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;6. API/Program.cs – Register Dependencies&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using CleanArchitectureDemo.Application.Interfaces;
using CleanArchitectureDemo.Application.UseCases;
using CleanArchitectureDemo.Infrastructure.Repositories;

var builder = WebApplication.CreateBuilder(args);

// Dependency Injection
builder.Services.AddScoped&amp;lt;IUserRepository, InMemoryUserRepository&amp;gt;();
builder.Services.AddScoped&amp;lt;UserService&amp;gt;();

builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

var app = builder.Build();

app.UseSwagger();
app.UseSwaggerUI();

app.MapControllers();
app.Run();

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;Thanks &lt;br&gt;
Keep Coding.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>dotnet</category>
      <category>cleancode</category>
      <category>cleancoding</category>
    </item>
    <item>
      <title>Reduce the page execution time</title>
      <dc:creator>Ravi Vishwakarma</dc:creator>
      <pubDate>Sun, 06 Apr 2025 18:32:50 +0000</pubDate>
      <link>https://forem.com/ravivis13370227/reduce-the-time-of-page-execution-15gh</link>
      <guid>https://forem.com/ravivis13370227/reduce-the-time-of-page-execution-15gh</guid>
      <description>&lt;p&gt;Alright, you're aiming for top-notch Core Web Vitals — crisp, smooth, fast-loading webpages that make Lighthouse go “WOW” and Google rank you like royalty 👑. Let’s break down the best practices to write HTML, CSS, JS, fonts, etc. that give you green scores across all Web Vitals:&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;HTML: Keep it Clean, Semantic &amp;amp; Lightweight&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
&amp;lt;head&amp;gt;
  &amp;lt;meta charset="UTF-8" /&amp;gt;
  &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1" /&amp;gt;
  &amp;lt;title&amp;gt;Your Awesome Page&amp;lt;/title&amp;gt;

  &amp;lt;!-- Preconnects for performance --&amp;gt;
  &amp;lt;link rel="preconnect" href="https://fonts.googleapis.com" /&amp;gt;
  &amp;lt;link rel="preconnect" href="https://fonts.gstatic.com" crossorigin /&amp;gt;

  &amp;lt;!-- Inline Critical CSS --&amp;gt;
  &amp;lt;style&amp;gt;
    /* Only critical styles here (for above-the-fold content) */
    body {
      font-family: 'Inter', sans-serif;
      margin: 0;
      padding: 0;
      background: #fff;
      color: #333;
    }
    h1 {
      font-size: 2rem;
      text-align: center;
      margin-top: 2rem;
    }
  &amp;lt;/style&amp;gt;

  &amp;lt;!-- Load fonts properly --&amp;gt;
  &amp;lt;link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;700&amp;amp;display=swap" rel="stylesheet" /&amp;gt;

  &amp;lt;!-- Defer non-critical CSS --&amp;gt;
  &amp;lt;link rel="stylesheet" href="styles.css" media="print" onload="this.media='all'" /&amp;gt;
  &amp;lt;noscript&amp;gt;&amp;lt;link rel="stylesheet" href="styles.css" /&amp;gt;&amp;lt;/noscript&amp;gt;

  &amp;lt;!-- Important: Avoid large JS in &amp;lt;head&amp;gt; --&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;

  &amp;lt;h1&amp;gt;Hello, Web Vitals!&amp;lt;/h1&amp;gt;
  &amp;lt;button id="btn"&amp;gt;Click Me&amp;lt;/button&amp;gt;

  &amp;lt;!-- Minimal Critical JS (inlined) --&amp;gt;
  &amp;lt;script&amp;gt;
    document.addEventListener('DOMContentLoaded', () =&amp;gt; {
      document.getElementById('btn').addEventListener('click', () =&amp;gt; {
        alert('Hi there!');
      });
    });
  &amp;lt;/script&amp;gt;

  &amp;lt;!-- Async/defer all non-critical JS --&amp;gt;
  &amp;lt;script src="main.js" defer&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;&lt;strong&gt;CSS: Optimize, Minify &amp;amp; Use Only What’s Needed&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Extract Critical CSS and inline it (manually or with tools like critical)&lt;/li&gt;
&lt;li&gt;Load the rest asynchronously (media="print" trick)&lt;/li&gt;
&lt;li&gt;Avoid unused styles (Lighthouse can show you these)&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;:where()&lt;/code&gt; or &lt;code&gt;:is()&lt;/code&gt; instead of long selector chains (faster parsing)&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;&lt;strong&gt;JavaScript: Split, Defer, and Delay&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Inline only critical JS&lt;/li&gt;
&lt;li&gt;Use defer for everything else&lt;/li&gt;
&lt;li&gt;Use code splitting (in frameworks like React, Vue, etc.)&lt;/li&gt;
&lt;li&gt;Avoid large JS bundles — aim for &amp;lt;150KB (gzipped) for initial load&lt;/li&gt;
&lt;li&gt;Lazy-load expensive features like charts, sliders, chat widgets&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;&lt;strong&gt;Fonts: Load Fast and Avoid Layout Shifts&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Use &lt;code&gt;font-display: swap&lt;/code&gt; (default with Google Fonts)&lt;/li&gt;
&lt;li&gt;Preconnect to &lt;code&gt;fonts.googleapis.com&lt;/code&gt; and &lt;code&gt;fonts.gstatic.com&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Prefer system fonts for super-fast load (optional)
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;700&amp;amp;display=swap');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;OR use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;&lt;strong&gt;Images: Compress, Lazy Load, Responsive&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;img src="banner.jpg" loading="lazy" alt="Banner" width="600" height="400" /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Use &lt;code&gt;loading="lazy"&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Add width and height attributes to prevent CLS (layout shift)&lt;/li&gt;
&lt;li&gt;Prefer &lt;code&gt;WebP&lt;/code&gt; or &lt;code&gt;AVIF&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;srcset&lt;/code&gt;for responsive images if needed&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;&lt;strong&gt;Core Web Vitals Targets (What You’re Chasing)&lt;/strong&gt;&lt;br&gt;
Metric                          Goal&lt;br&gt;
LCP (Largest Contentful Paint)  &amp;lt; 2.5s&lt;br&gt;
FID (First Input Delay)         &amp;lt; 100ms&lt;br&gt;
CLS (Cumulative Layout Shift)   &amp;lt; 0.1&lt;br&gt;
TTI (Time to Interactive)   As fast as possible&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Read More&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://dev.to/ravivis13370227/comprehensive-guide-to-documentation-comments-in-c-379d"&gt;Comprehensive Guide to Documentation Comments in C#&lt;/a&gt;&lt;br&gt;
&lt;a href="https://dev.to/ravivis13370227/understanding-strong-password-regex-in-c-from-basic-to-advanced-25cf"&gt;Understanding Strong Password Regex in C#: From Basic to Advanced&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;Thank You,&lt;br&gt;
Keep coding&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Understanding Strong Password Regex in C#: From Basic to Advanced</title>
      <dc:creator>Ravi Vishwakarma</dc:creator>
      <pubDate>Mon, 03 Feb 2025 13:09:57 +0000</pubDate>
      <link>https://forem.com/ravivis13370227/understanding-strong-password-regex-in-c-from-basic-to-advanced-25cf</link>
      <guid>https://forem.com/ravivis13370227/understanding-strong-password-regex-in-c-from-basic-to-advanced-25cf</guid>
      <description>&lt;h3&gt;
  
  
  Introduction
&lt;/h3&gt;

&lt;p&gt;In today’s digital age, ensuring password security is a critical aspect of software development. One way to enforce security standards is by using regular expressions (Regex) to validate passwords. In this article, we will explore different levels of password complexity, ranging from basic to advanced, using C#.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;1. Basic Password Validation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A basic password validation rule simply enforces a minimum length. The following Regex pattern ensures that a password is at least 8 characters long:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string basicRegex = "^.{8,}$";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Explanation:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;^&lt;/code&gt; and &lt;code&gt;$&lt;/code&gt; mark the start and end of the string.&lt;/li&gt;
&lt;li&gt;.{8,} ensures the password has at least 8 characters of any type.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;While this rule prevents extremely short passwords, it does not enforce complexity.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;2. Intermediate Password Validation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To increase security, we can require passwords to contain at least one letter and one digit:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string intermediateRegex = "^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,}$";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Explanation:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;(?=.*[A-Za-z])&lt;/code&gt; ensures at least one letter (uppercase or lowercase).&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;(?=.*\d)&lt;/code&gt; ensures at least one digit.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;[A-Za-z\d]{8,}&lt;/code&gt; allows only letters and digits, with a minimum of 8 characters.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This regex prevents purely numeric or alphabetical passwords but still lacks special character enforcement.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;3. Advanced Password Validation (Strong Passwords)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A strong password should meet the following criteria:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;At least 8 characters long.&lt;/li&gt;
&lt;li&gt;Contains at least one lowercase letter.&lt;/li&gt;
&lt;li&gt;Contains at least one uppercase letter.&lt;/li&gt;
&lt;li&gt;Contains at least one digit.&lt;/li&gt;
&lt;li&gt;Contains at least one special character from a predefined set (e.g., @$!%*?&amp;amp;).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Regex for Strong Passwords:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string advancedRegex = "^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&amp;amp;])[A-Za-z\d@$!%*?&amp;amp;]{8,}$";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string extendedAdvancedRegex = "^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&amp;amp;^#()[\]{}|\\/\-+_.:;=,~`])[^\s&amp;lt;&amp;gt;]{8,}$";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Explanation:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;(?=.*[a-z])&lt;/code&gt; ensures at least one lowercase letter.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;(?=.*[A-Z])&lt;/code&gt; ensures at least one uppercase letter.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;(?=.*\d)&lt;/code&gt; ensures at least one digit.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;(?=.*[@$!%*?&amp;amp;])&lt;/code&gt; ensures at least one special character.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;(?=.*[@$!%*?&amp;amp;^#()[\]{}|\\/\-+_.:;=,~])&lt;/code&gt; ensures at least one special character from an extended set.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;[^\s&amp;lt;&amp;gt;]{8,}&lt;/code&gt; ensures a minimum length of 8 characters while restricting whitespace and certain unsafe characters.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This pattern significantly enhances password security and meets most modern security standards.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;4. Implementing Password Validation in C#&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Below is a simple C# program that validates passwords using Regex:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using System;
using System.Text.RegularExpressions;

public class PasswordValidator
{
    public static bool IsValidPassword(string password, string pattern)
    {
        return Regex.IsMatch(password, pattern);
    }

    public static void Main()
    {
        string password = "StrongP@ss1";

        // Use one of the regex patterns defined above
        string pattern = "^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&amp;amp;^#()[\]{}|\\/\-+_.:;=,~`])[^\s&amp;lt;&amp;gt;]{8,}$";

        if (IsValidPassword(password, pattern))
            Console.WriteLine("Password is valid!");
        else
            Console.WriteLine("Password does not meet the requirements.");
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Implementing password validation using Regex in C# ensures strong security policies for user authentication. By progressively enforcing length, character variety, and complexity, we can significantly reduce vulnerabilities related to weak passwords.&lt;/p&gt;

&lt;p&gt;For enterprise-level applications, additional security measures such as multi-factor authentication (MFA) and rate-limiting login attempts should also be implemented alongside Regex-based password validation.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Connect with Me!&lt;/strong&gt;&lt;br&gt;
Thanks for reading! If you found this helpful, consider following me for more content like this.&lt;/p&gt;

&lt;p&gt;🌟 &lt;a href="https://www.linkedin.com/in/ravi-vishwakarma-a20b451b6/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;&lt;br&gt;
💻 &lt;a href="https://github.com/ravivish786" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Your support motivates me to keep sharing valuable insights. Stay tuned for more! 🚀&lt;/p&gt;

&lt;p&gt;Thanks for Reading.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>AddMVC() vs AddControllersWithViews() vs AddControllers() vs AddRazorPages() | ASP.Net Core</title>
      <dc:creator>Ravi Vishwakarma</dc:creator>
      <pubDate>Tue, 28 Jan 2025 02:42:18 +0000</pubDate>
      <link>https://forem.com/ravivis13370227/addmvc-vs-addcontrollerswithviews-vs-addcontrollers-vs-addrazorpages-aspnet-core-bgo</link>
      <guid>https://forem.com/ravivis13370227/addmvc-vs-addcontrollerswithviews-vs-addcontrollers-vs-addrazorpages-aspnet-core-bgo</guid>
      <description>&lt;p&gt;In ASP.NET Core, the methods &lt;code&gt;AddMvc()&lt;/code&gt;, &lt;code&gt;AddControllersWithViews()&lt;/code&gt;, &lt;code&gt;AddControllers()&lt;/code&gt;, and &lt;code&gt;AddRazorPages()&lt;/code&gt; are used to configure services for various application architectures. Each of these methods serves a specific purpose depending on the type of application you are building.&lt;/p&gt;




&lt;h3&gt;
  
  
  AddMvc()
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Purpose&lt;/strong&gt;: Configures the app to use the complete ASP.NET Core MVC framework, including support for controllers, views, Razor Pages, and API features.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Status&lt;/strong&gt;: This method is obsolete in recent ASP.NET Core versions (3.0 and later). It's replaced by more granular methods like AddControllersWithViews() or AddRazorPages().&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Use Case&lt;/strong&gt;: Used in older versions (before ASP.NET Core 3.0) to set up both MVC and Razor Pages in a single step.&lt;/p&gt;




&lt;h3&gt;
  
  
  AddControllersWithViews()
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Purpose&lt;/strong&gt;: Configures the app to support controllers and views (for MVC-style web apps). Does not include Razor Pages.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Use Case&lt;/strong&gt;: Ideal for traditional MVC web applications where controllers and views are the primary focus.&lt;br&gt;
Suitable for server-rendered HTML with routing, model binding, and validation.&lt;br&gt;
&lt;strong&gt;Features&lt;/strong&gt;: Adds support for controllers and views.&lt;br&gt;
Does not support Razor Pages (e.g., .cshtml files under the /Pages folder).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;builder.Services.AddControllersWithViews();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  AddControllers()
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Purpose&lt;/strong&gt;: Configures the app to support controllers only, for building API applications without views.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Use Case&lt;/strong&gt;: Suitable for building Web APIs. Does not include Razor Pages or support for views.&lt;br&gt;
&lt;strong&gt;Features&lt;/strong&gt;: Adds support for controllers, but excludes Razor Pages and views. Focused on API endpoints, ideal for RESTful services.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;builder.Services.AddControllers();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  AddRazorPages()
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Purpose&lt;/strong&gt;: Configures the app to support Razor Pages, a page-focused programming model.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Use Case&lt;/strong&gt;: Ideal for applications primarily using Razor Pages for server-side rendering. Suitable for smaller apps or apps with a page-oriented architecture (e.g., intranet applications).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Features&lt;/strong&gt;:&lt;br&gt;
Supports Razor Pages (e.g., .cshtml files under the /Pages folder).&lt;br&gt;
Does not support controllers or views unless explicitly added.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;builder.Services.AddRazorPages();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  .NET Core Middleware Comparison Table
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;strong&gt;Method&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Controllers&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Views&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Razor Pages&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;APIs (JSON/XML responses)&lt;/strong&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;AddMvc()&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;AddControllersWithViews()&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;AddControllers()&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;AddRazorPages()&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h3&gt;
  
  
  Choosing the Right Method
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;For APIs:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use &lt;code&gt;AddControllers()&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Example: Building a RESTful API that does not require views or Razor Pages.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;For Traditional MVC Applications:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use &lt;code&gt;AddControllersWithViews()&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Example: Building a web app with controllers and views for server-side rendering.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;For Razor Pages Applications:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use &lt;code&gt;AddRazorPages()&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Example: Building a simple page-oriented application with &lt;code&gt;.cshtml&lt;/code&gt; files under &lt;code&gt;/Pages&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;For Hybrid Scenarios:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Combine &lt;code&gt;AddControllersWithViews()&lt;/code&gt; and &lt;code&gt;AddRazorPages()&lt;/code&gt; for apps that need both controllers and Razor Pages.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;builder.Services.AddControllersWithViews();
builder.Services.AddRazorPages();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Best Practices
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Use specific configurations (e.g., &lt;code&gt;AddControllersWithViews()&lt;/code&gt;, &lt;code&gt;AddRazorPages()&lt;/code&gt;) instead of &lt;code&gt;AddMvc()&lt;/code&gt; for better clarity and performance.&lt;/li&gt;
&lt;li&gt;Choose the appropriate method based on your application's architecture and the required features.&lt;/li&gt;
&lt;li&gt;If your app includes API endpoints and views, combine &lt;code&gt;AddControllersWithViews()&lt;/code&gt; with features like &lt;code&gt;JsonOptions&lt;/code&gt; to configure API behavior.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;strong&gt;Connect with Me!&lt;/strong&gt;&lt;br&gt;
Thanks for reading! If you found this helpful, consider following me for more content like this.&lt;/p&gt;

&lt;p&gt;🌟 &lt;a href="https://www.linkedin.com/in/ravi-vishwakarma-a20b451b6/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;&lt;br&gt;
💻 &lt;a href="https://github.com/ravivish786" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Your support motivates me to keep sharing valuable insights. Stay tuned for more! 🚀&lt;/p&gt;

&lt;p&gt;Thanks for Reading.&lt;/p&gt;

</description>
      <category>netcore</category>
      <category>dotnet</category>
      <category>csharp</category>
    </item>
    <item>
      <title>Comprehensive Guide to Documentation Comments in C#</title>
      <dc:creator>Ravi Vishwakarma</dc:creator>
      <pubDate>Sun, 19 Jan 2025 11:20:09 +0000</pubDate>
      <link>https://forem.com/ravivis13370227/comprehensive-guide-to-documentation-comments-in-c-379d</link>
      <guid>https://forem.com/ravivis13370227/comprehensive-guide-to-documentation-comments-in-c-379d</guid>
      <description>&lt;p&gt;Documentation comments in C# are structured comments that describe code functionality and are processed by tools like Visual Studio and Sandcastle to generate user-friendly documentation. These comments are written in XML format and placed above code elements like classes, methods, properties, and fields.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Syntax for Documentation Comments in C#&lt;/strong&gt;&lt;br&gt;
In C#, documentation comments start with three slashes (&lt;code&gt;///&lt;/code&gt;) and support XML-based tags to provide detailed descriptions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/// &amp;lt;summary&amp;gt;
/// Represents a basic calculator for arithmetic operations.
/// &amp;lt;/summary&amp;gt;
public class Calculator
{
    // Class implementation
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Common XML Tags in C#&lt;/strong&gt;&lt;br&gt;
Here are the most commonly used XML tags in C# documentation comments:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;General Tags&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;summary&amp;gt;&lt;/code&gt;:   Provides a brief summary of a class, method, or property.&lt;br&gt;
&lt;code&gt;&amp;lt;remarks&amp;gt;&lt;/code&gt;:   Adds additional or detailed remarks about the element.&lt;br&gt;
&lt;code&gt;&amp;lt;example&amp;gt;&lt;/code&gt;:   Contains code examples to demonstrate usage.&lt;br&gt;
&lt;code&gt;&amp;lt;value&amp;gt;&lt;/code&gt;: Describes the value returned by a property.&lt;br&gt;
&lt;code&gt;&amp;lt;inheritdoc&amp;gt;&lt;/code&gt;:    Inherits documentation from the base class or interface.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Method-Specific Tags&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;param&amp;gt;&lt;/code&gt;: Describes a method parameter.&lt;br&gt;
&lt;code&gt;&amp;lt;returns&amp;gt;&lt;/code&gt;:   Documents the return value of a method.&lt;br&gt;
&lt;code&gt;&amp;lt;exception&amp;gt;&lt;/code&gt;: Describes exceptions thrown by the method.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cross-Referencing Tags&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;see&amp;gt;&lt;/code&gt;:   Links to another code element for inline reference.&lt;br&gt;
&lt;code&gt;&amp;lt;seealso&amp;gt;&lt;/code&gt;:   Refers to related code elements for more information.&lt;br&gt;
&lt;code&gt;&amp;lt;c&amp;gt;&lt;/code&gt;: Embeds inline code.&lt;br&gt;
&lt;code&gt;&amp;lt;code&amp;gt;&lt;/code&gt;:  Displays a block of code in the documentation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Examples of Documentation Comments in C#&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Documenting a Class&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/// &amp;lt;summary&amp;gt;
/// Performs basic arithmetic operations such as addition and subtraction.
/// &amp;lt;/summary&amp;gt;
/// &amp;lt;remarks&amp;gt;
/// This class is intended for demonstration purposes only.
/// &amp;lt;/remarks&amp;gt;
public class Calculator
{
    // Class implementation
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Documenting a Method&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/// &amp;lt;summary&amp;gt;
/// Adds two integers and returns the result.
/// &amp;lt;/summary&amp;gt;
/// &amp;lt;param name="a"&amp;gt;The first integer.&amp;lt;/param&amp;gt;
/// &amp;lt;param name="b"&amp;gt;The second integer.&amp;lt;/param&amp;gt;
/// &amp;lt;returns&amp;gt;The sum of the two integers.&amp;lt;/returns&amp;gt;
/// &amp;lt;exception cref="ArgumentNullException"&amp;gt;Thrown if a or b is null.&amp;lt;/exception&amp;gt;
public int Add(int a, int b)
{
    if (a == null || b == null)
    {
        throw new ArgumentNullException("Parameters cannot be null.");
    }
    return a + b;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Documenting a Property&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/// &amp;lt;summary&amp;gt;
/// Gets or sets the name of the calculator's manufacturer.
/// &amp;lt;/summary&amp;gt;
/// &amp;lt;value&amp;gt;
/// A string representing the manufacturer's name.
/// &amp;lt;/value&amp;gt;
public string Manufacturer { get; set; }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Documenting an Example&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/// &amp;lt;example&amp;gt;
/// &amp;lt;code&amp;gt;
/// Calculator calc = new Calculator();
/// int result = calc.Add(5, 10);
/// Console.WriteLine(result); // Output: 15
/// &amp;lt;/code&amp;gt;
/// &amp;lt;/example&amp;gt;
public int Add(int a, int b)
{
    return a + b;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Best Practices for Documentation Comments in C#&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Write Clear Summaries&lt;/strong&gt;: Use  to describe the purpose of a code element in a concise and meaningful way.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use  and  Tags Appropriately&lt;/strong&gt;: Ensure all method parameters and return values are documented.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Provide Examples&lt;/strong&gt;: Use  tags to demonstrate usage, especially for complex methods.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Link to Related Elements&lt;/strong&gt;: Utilize  and  to refer readers to related parts of the codebase.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Maintain Consistency&lt;/strong&gt;: Follow consistent formatting and style for all documentation comments.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Update Regularly&lt;/strong&gt;: Sync documentation comments with code changes to prevent inaccuracies.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For more go to Microsoft &lt;a href="https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/xmldoc/" rel="noopener noreferrer"&gt;Documentation&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thanks for reading.&lt;/p&gt;

</description>
      <category>csharp</category>
      <category>aspdotnet</category>
      <category>netcore</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Global Class Validator for Enhanced Object Validation in EMS</title>
      <dc:creator>Ravi Vishwakarma</dc:creator>
      <pubDate>Sun, 19 Jan 2025 10:01:25 +0000</pubDate>
      <link>https://forem.com/ravivis13370227/global-class-validator-for-enhanced-object-validation-in-ems-5hjh</link>
      <guid>https://forem.com/ravivis13370227/global-class-validator-for-enhanced-object-validation-in-ems-5hjh</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introducing Global Class Validator: Streamlined Object Validation for Employee Management Systems&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Validation is a critical aspect of any application that handles structured data. To ensure accuracy, consistency, and compliance with business logic, validation must be seamless and reliable.&lt;/p&gt;

&lt;p&gt;Our Global Class Validator is a powerful utility tailored for .NET applications, particularly useful in systems like the Employee Management System. It simplifies object validation by leveraging .NET’s built-in &lt;code&gt;ValidationAttribute&lt;/code&gt;and ensures that your data meets defined standards effortlessly.&lt;/p&gt;

&lt;h4&gt;
  
  
  Key Features
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Thread-Safe Error Tracking&lt;/strong&gt;: Errors are captured and stored in a thread-safe manner, ensuring accurate results even in multi-threaded environments.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dynamic Property Validation&lt;/strong&gt;: The validator dynamically inspects all public properties of an object and applies the associated &lt;code&gt;ValidationAttribute&lt;/code&gt;to validate their values.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Comprehensive Error Handling&lt;/strong&gt;: The tool provides methods to retrieve errors in multiple formats:&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;GetErrors&lt;/code&gt;: Returns a collection of validation errors for detailed inspection.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;GetErrorsString&lt;/code&gt;: Provides a string-formatted summary of all validation errors.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;4.&lt;strong&gt;Ease of Use&lt;/strong&gt;: Add a simple &lt;code&gt;IsValid&lt;/code&gt;method to your model, and the validator will handle everything from validation checks to error aggregation.&lt;/p&gt;

&lt;h4&gt;
  
  
  Sample Usage
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualBasic;

namespace Employee_Management_System
{
    internal class EmployeeModel
    {
        public EmployeeModel() { }

        [Required]
        [Range(0, uint.MaxValue)]
        public int EmployeeID { get; set; }

        [Required]
        [StringLength(100, MinimumLength = 2)]
        public string Name { get; set; }

        [Required]
        public string Designation { get; set; }

        [Required]
        public string Department { get; set; }

        [Required]
        [RegularExpression(@"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$", ErrorMessage = "Please enter valid EmailID. ")]
        public string Email { get; set; }

        [Required]
        [RegularExpression(@"^\d{8,}$", ErrorMessage = "Please enter valid PhoneNumber. ")]
        public string Phone { get; set; }

        [Required]
        public DateTime JoiningDate { get; set; }

        public EmployeeModel(int employeeID, string name, string designation, string department, string email, string phone, DateTime joiningDate)
        {
            EmployeeID = employeeID;
            Name = name;
            Designation = designation;
            Department = department;
            Email = email;
            Phone = phone;
            JoiningDate = joiningDate;
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here’s how you can integrate and use the Global Class Validator in your .NET projects:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var employee = new EmployeeModel { Name = "", Email = "develop" }; // Example model with errors  

bool IsValid = ClassModelValidator&amp;lt;EmployeeModel&amp;gt;.IsValid(employee);

if (!IsValid)
{
     MessageBox.Show( ClassModelValidator&amp;lt;EmployeeModel&amp;gt;.GetErrorsString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Code Implementation
&lt;/h4&gt;

&lt;p&gt;Below is the full implementation of the &lt;code&gt;GlobalClassValidator&lt;/code&gt; class for your reference:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security.Policy;
using System.Text;
using System.Threading.Tasks;

namespace Employee_Management_System.Helper
{
    public static class ClassModelValidator&amp;lt;T&amp;gt; where T : class
    {
        // Errors list for tracking validation issues
        [ThreadStatic]
        private static List&amp;lt;string&amp;gt; Errors;

        static ClassModelValidator()
        {
            Errors = new List&amp;lt;string&amp;gt;();
        }



        public static bool IsValid(T model)
        {
            if (model == null)
            {
                AddError("Model cannot be null.");
                return false;
            }

            Errors.Clear();

            foreach (var property in typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance))
            {
                var value = property.GetValue(model);
                foreach (var attribute in property.GetCustomAttributes&amp;lt;ValidationAttribute&amp;gt;())
                {
                    if (!attribute.IsValid(value))
                    {
                        AddError(attribute.FormatErrorMessage(property.Name));
                    }
                }
            }

            return Errors.Count == 0;
        }

        public static IEnumerable&amp;lt;string&amp;gt; GetErrors()
        {
            return Errors;
        }

        public static string GetErrorsString()
        {
            return string.Join(Environment.NewLine, Errors);
        }

        private static void AddError(string error)
        {
            if (!string.IsNullOrEmpty(error))
            {
                Errors.Add(error);
            }
        }
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Benefits of Using Global Class Validator
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Enhances data integrity with minimal overhead.&lt;/li&gt;
&lt;li&gt;Reduces boilerplate code by utilizing reflection and attributes.&lt;/li&gt;
&lt;li&gt;Easily extensible for specific validation requirements.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With the Global Class Validator, you can ensure that your Employee Management System is robust, efficient, and error-free.&lt;/p&gt;

&lt;p&gt;Feel free to integrate this utility into your projects and let us know how it transforms your validation processes!&lt;/p&gt;

&lt;p&gt;Thanks for Reading!&lt;/p&gt;

&lt;p&gt;For more details, visit:&lt;br&gt;
🔗 &lt;a href="https://github.com/ravivish786/Employee-Management-System-Unicode" rel="noopener noreferrer"&gt;Employee Management System on GitHub&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Direct link to the code:&lt;br&gt;
🔗 &lt;a href="https://github.com/ravivish786/Employee-Management-System-Unicode/blob/master/Employee-Management-System/Helper/ClassModelValidator.cs" rel="noopener noreferrer"&gt;ClassModelValidator.cs&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Feel free to explore the repository and contribute! 🚀&lt;/p&gt;

</description>
      <category>csharp</category>
      <category>dotnet</category>
      <category>aspdotnet</category>
      <category>core</category>
    </item>
    <item>
      <title>Generate SEO-Friendly Slugs from Titles in ASP.NET Core</title>
      <dc:creator>Ravi Vishwakarma</dc:creator>
      <pubDate>Sun, 05 Jan 2025 09:50:55 +0000</pubDate>
      <link>https://forem.com/ravivis13370227/generate-seo-friendly-slugs-from-titles-in-aspnet-core-47o9</link>
      <guid>https://forem.com/ravivis13370227/generate-seo-friendly-slugs-from-titles-in-aspnet-core-47o9</guid>
      <description>&lt;p&gt;To create shorter, user-friendly, or "slugged" URLs with Latin-based names, you can use URL slugging. This process typically involves converting strings (like page titles or names) into lowercase, replacing spaces and special characters with hyphens or other valid URL characters, and ensuring the resulting URL is unique and human-readable.&lt;/p&gt;

&lt;h2&gt;
  
  
  Example: Generating Latin Name Slugs for URLs in ASP.NET Core
&lt;/h2&gt;




&lt;h3&gt;
  
  
  Create a Utility Method for Slug Generation
&lt;/h3&gt;

&lt;p&gt;A utility method can convert any string into a slug-friendly format.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using System.Text;
using System.Text.RegularExpressions;
public static class UrlSlugger
{
    public static string GenerateSlug(string input)
    {
        if (string.IsNullOrEmpty(input))
            return string.Empty;

        // Convert to lowercase
        input = input.ToLowerInvariant();

        // Remove diacritics (accents) from Latin characters
        input = RemoveDiacritics(input);

        // Replace spaces and invalid characters with hyphens
        input = Regex.Replace(input, @"[^a-z0-9\s-]", ""); // Allow only alphanumeric, spaces, and hyphens
        input = Regex.Replace(input, @"\s+", "-").Trim();  // Replace spaces with hyphens
        input = Regex.Replace(input, @"-+", "-");         // Replace multiple hyphens with a single one

        return input;
    }

    private static string RemoveDiacritics(string text)
    {
        var normalizedString = text.Normalize(NormalizationForm.FormD);
        var stringBuilder = new StringBuilder();

        foreach (var c in normalizedString)
        {
            var unicodeCategory = System.Globalization.CharUnicodeInfo.GetUnicodeCategory(c);
            if (unicodeCategory != System.Globalization.UnicodeCategory.NonSpacingMark)
            {
                stringBuilder.Append(c);
            }
        }

        return stringBuilder.ToString().Normalize(NormalizationForm.FormC);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Using the Slug Generator in Your Application
&lt;/h3&gt;

&lt;p&gt;You can use this slug generator for URLs when defining routes or generating links dynamically.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example in Controller:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public IActionResult GenerateSluggedUrl(string title)
{
    string slug = UrlSlugger.GenerateSlug(title);
    return Ok($"Generated slug: {slug}");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Example Usage:&lt;/strong&gt;&lt;br&gt;
For a title like "Éxample Title for URL!", the slug will be:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;example-title-for-url&lt;/p&gt;
&lt;/blockquote&gt;


&lt;h3&gt;
  
  
  Integrating Slugs in Routing
&lt;/h3&gt;

&lt;p&gt;To use slugs in your routing, you can define a route pattern with a {slug} parameter and parse the slug dynamically.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example in Program.cs:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.UseEndpoints(endpoints =&amp;gt;
{
    endpoints.MapControllerRoute(
        name: "sluggedRoute",
        pattern: "page/{slug}",
        defaults: new { controller = "Page", action = "Details" });

    // Default route
    endpoints.MapControllerRoute(
        name: "default",
        pattern: "{controller=Home}/{action=Index}/{id?}");
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Example in PageController:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class PageController : Controller
{
    public IActionResult Details(string slug)
    {
        // Retrieve the page data by the slug
        return View(model: $"Page with slug: {slug}");
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Testing Slugged URLs
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Example URLs:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;/page/example-title-for-url&lt;/code&gt;&lt;br&gt;
&lt;code&gt;/page/sample-page-title&lt;/code&gt;&lt;br&gt;
&lt;strong&gt;Result:&lt;/strong&gt;&lt;br&gt;
You can use the slug parameter in the controller to load content based on the slug (e.g., querying the database for matching pages).&lt;/p&gt;




&lt;h3&gt;
  
  
  Additional Tips
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Ensure slugs are unique for your content. Add a database field to store slugs and validate uniqueness.&lt;/li&gt;
&lt;li&gt;Store slugs in your database alongside the corresponding entity (e.g., articles, pages, or products).&lt;/li&gt;
&lt;li&gt;Use slugs in links to improve SEO and user experience.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Thanks&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Roman to Integer</title>
      <dc:creator>Ravi Vishwakarma</dc:creator>
      <pubDate>Wed, 25 Dec 2024 10:12:00 +0000</pubDate>
      <link>https://forem.com/ravivis13370227/roman-to-integer-87l</link>
      <guid>https://forem.com/ravivis13370227/roman-to-integer-87l</guid>
      <description>&lt;p&gt;Roman numerals, originating from ancient Rome, utilize combinations of Latin letters to represent values:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;I = 1&lt;/li&gt;
&lt;li&gt;V = 5&lt;/li&gt;
&lt;li&gt;X = 10&lt;/li&gt;
&lt;li&gt;L = 50&lt;/li&gt;
&lt;li&gt;C = 100&lt;/li&gt;
&lt;li&gt;D = 500&lt;/li&gt;
&lt;li&gt;M = 1000&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Typically, numerals are written from largest to smallest from left to right. However, to represent numbers like 4 and 9, a subtractive notation is used, where a smaller numeral precedes a larger one, indicating subtraction. For example, IV represents 4 (5 - 1), and IX represents 9 (10 - 1). &lt;br&gt;
MEDIUM&lt;/p&gt;

&lt;p&gt;To convert a Roman numeral to an integer, follow these steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Initialize a total sum to zero.&lt;/li&gt;
&lt;li&gt;Traverse the Roman numeral from left to right.&lt;/li&gt;
&lt;li&gt;For each symbol:&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;If its value is less than the value of the next symbol, subtract it from the total.&lt;/li&gt;
&lt;li&gt;Otherwise, add its value to the total.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This method accounts for both additive and subtractive combinations in Roman numerals. &lt;/p&gt;

&lt;p&gt;For example, to convert "MCMXCIV" to an integer:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;M (1000)&lt;/li&gt;
&lt;li&gt;CM (900)&lt;/li&gt;
&lt;li&gt;XC (90)&lt;/li&gt;
&lt;li&gt;IV (4)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Adding these values together: 1000 + 900 + 90 + 4 = 1994.&lt;/p&gt;

&lt;p&gt;This approach ensures accurate conversion of Roman numerals to their integer equivalents.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example 1&lt;/strong&gt;&lt;br&gt;
`&lt;br&gt;
using System;&lt;br&gt;
class Program&lt;br&gt;
{&lt;br&gt;
    static void Main()&lt;br&gt;
    {&lt;br&gt;
        string roman = "MCMXCIV"; // Example Roman numeral&lt;br&gt;
        int result = RomanToInt(roman);&lt;br&gt;
        Console.WriteLine($"The integer value of {roman} is {result}.");&lt;br&gt;
    }&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;static int RomanToInt(string s)
{
    int total = 0;
    int prevValue = 0;

    foreach (char c in s)
    {
        int currentValue = RomanCharToValue(c);

        if (currentValue &amp;gt; prevValue)
        {
            // Subtract twice the previous value since it was added earlier
            total += currentValue - 2 * prevValue;
        }
        else
        {
            total += currentValue;
        }

        prevValue = currentValue;
    }

    return total;
}

static int RomanCharToValue(char c)
{
    switch (c)
    {
        case 'I': return 1;
        case 'V': return 5;
        case 'X': return 10;
        case 'L': return 50;
        case 'C': return 100;
        case 'D': return 500;
        case 'M': return 1000;
        default: throw new ArgumentException("Invalid Roman numeral character");
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;`&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example 2&lt;/strong&gt;&lt;br&gt;
`&lt;br&gt;
class RomanToInt {&lt;br&gt;
    public static int _RomanToInt(string s)&lt;br&gt;
    {&lt;br&gt;
        int total = 0, prevValue = 0, currentValue = 0;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    for (int i = s.Length - 1; i &amp;gt;= 0; i--)
    {
        switch (s[i])
        {
            case 'I':  currentValue =  1; break;;
            case 'V': currentValue =  5; break;;
            case 'X': currentValue =  10; break;;
            case 'L': currentValue =  50; break;;
            case 'C': currentValue =  100; break;;
            case 'D': currentValue =  500; break;;
            case 'M': currentValue =  1000; break;;
            default: throw new ArgumentException("Invalid Roman numeral character");
        }
        total = (currentValue &amp;gt; prevValue) ? (total + currentValue) : total - currentValue;
        prevValue = currentValue;
    }

    return total;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;`&lt;/p&gt;

&lt;p&gt;Thanks for Reading.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
