<?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>DEV Community: Shivanshu Sharma</title>
    <description>The latest articles on DEV Community by Shivanshu Sharma (@shivanshushady).</description>
    <link>https://dev.to/shivanshushady</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%2F1470551%2Fc48da66e-2b08-45be-8cfd-e4c20d096e29.jpeg</url>
      <title>DEV Community: Shivanshu Sharma</title>
      <link>https://dev.to/shivanshushady</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/shivanshushady"/>
    <language>en</language>
    <item>
      <title>Advantages of a HashSet over a List in C#</title>
      <dc:creator>Shivanshu Sharma</dc:creator>
      <pubDate>Wed, 08 May 2024 08:07:16 +0000</pubDate>
      <link>https://dev.to/shivanshushady/advantages-of-a-hashset-over-a-list-in-c-aj8</link>
      <guid>https://dev.to/shivanshushady/advantages-of-a-hashset-over-a-list-in-c-aj8</guid>
      <description>&lt;p&gt;&lt;strong&gt;Efficiency and Search Performance&lt;/strong&gt;:&lt;br&gt;
A HashSet is optimized for searching and provides faster lookup times compared to a List.&lt;br&gt;
When you need to check whether an element exists in the collection, a HashSet performs better due to its hash-based approach.&lt;br&gt;
The time complexity for adding, removing, and searching in a HashSet is O(1) (constant time), making it efficient even with large amounts of data1.&lt;br&gt;
&lt;strong&gt;Uniqueness&lt;/strong&gt;:&lt;br&gt;
A HashSet ensures that each element appears only once. It automatically handles duplicates by rejecting them.&lt;br&gt;
In contrast, a List allows duplicate elements, and you need to manually check for duplicates before adding an item.&lt;br&gt;
&lt;strong&gt;Set Operations&lt;/strong&gt;:&lt;br&gt;
A HashSet supports set operations like union, intersection, and set difference.&lt;br&gt;
For example, you can combine two HashSets using UnionWith, find common elements with IntersectWith, or remove elements with ExceptWith2.&lt;br&gt;
No Indexing:&lt;br&gt;
Unlike a List, a HashSet does not provide indexing capabilities. You cannot access elements by index.&lt;br&gt;
If you need to retrieve elements by position, a List is more suitable.&lt;br&gt;
Ordering:&lt;br&gt;
A List maintains the order of elements as they are inserted.&lt;br&gt;
A HashSet is an unordered collection and does not guarantee any specific sequence3.&lt;br&gt;
&lt;strong&gt;In summary&lt;/strong&gt;, use a HashSet when you prioritize uniqueness, fast lookups, and set operations. If you need indexing or maintain insertion order, consider using a List. Keep in mind that the choice depends on your specific use case and requirements!&lt;/p&gt;

</description>
      <category>csharp</category>
      <category>dotnet</category>
      <category>learning</category>
      <category>development</category>
    </item>
    <item>
      <title>Understand HashSet via Copilot</title>
      <dc:creator>Shivanshu Sharma</dc:creator>
      <pubDate>Wed, 08 May 2024 07:47:13 +0000</pubDate>
      <link>https://dev.to/shivanshushady/understand-hashset-via-copilot-2l5m</link>
      <guid>https://dev.to/shivanshushady/understand-hashset-via-copilot-2l5m</guid>
      <description>&lt;p&gt;I asked Copilot to help me understand Hashset, sharing with you=&amp;gt;&lt;/p&gt;

&lt;p&gt;A HashSet in C# is a powerful data structure that represents a set of values. Let me break it down for you:&lt;/p&gt;

&lt;p&gt;Definition:&lt;br&gt;
A HashSet is part of the System.Collections.Generic namespace in C#.&lt;br&gt;
It’s an unordered collection that contains unique elements.&lt;br&gt;
Unlike other collection types, a HashSet uses a hash table for storage, allowing for fast retrieval of elements.&lt;br&gt;
It does not maintain insertion order and cannot access elements by index.&lt;br&gt;
Key Features:&lt;br&gt;
Uniqueness: A HashSet ensures that each element appears only once.&lt;br&gt;
Performance: Adding and removing elements has constant time complexity.&lt;br&gt;
Set Operations: It implements mathematical set operations (e.g., union, intersection, etc.).&lt;br&gt;
Usage Example:&lt;br&gt;
C#&lt;/p&gt;

&lt;p&gt;// Create two HashSet objects&lt;br&gt;
HashSet evenNumbers = new HashSet();&lt;br&gt;
HashSet oddNumbers = new HashSet();&lt;/p&gt;

&lt;p&gt;// Populate evenNumbers with even numbers&lt;br&gt;
for (int i = 0; i &amp;lt; 5; i++)&lt;br&gt;
{&lt;br&gt;
    evenNumbers.Add(i * 2);&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;// Call UnionWith to merge oddNumbers into evenNumbers&lt;br&gt;
evenNumbers.UnionWith(oddNumbers);&lt;br&gt;
AI-generated code. Review and use carefully. More info on FAQ.&lt;br&gt;
You can find more information about the HashSet class in the official Microsoft Learn documentation or explore additional resources like this comprehensive guide or this tutorial. Happy coding! 🚀&lt;/p&gt;

</description>
      <category>csharp</category>
      <category>webdev</category>
      <category>learning</category>
      <category>githubcopilot</category>
    </item>
    <item>
      <title>IHttpClientFactory in C#.</title>
      <dc:creator>Shivanshu Sharma</dc:creator>
      <pubDate>Tue, 07 May 2024 17:19:51 +0000</pubDate>
      <link>https://dev.to/shivanshushady/ihttpclientfactory-in-c-3a23</link>
      <guid>https://dev.to/shivanshushady/ihttpclientfactory-in-c-3a23</guid>
      <description>&lt;p&gt;The IHttpClientFactory is a powerful feature introduced in .NET Core 2.1 that simplifies the management of HttpClient instances. Here are some key points about it:&lt;/p&gt;

&lt;p&gt;What is IHttpClientFactory?&lt;br&gt;
The IHttpClientFactory serves as a factory abstraction for creating HttpClient instances with custom configurations.&lt;br&gt;
It’s designed to work seamlessly with dependency injection (DI), logging, and configuration in .NET applications.&lt;br&gt;
By using IHttpClientFactory, you can avoid common pitfalls related to manual management of HttpClient instances.&lt;br&gt;
Benefits of IHttpClientFactory:&lt;br&gt;
Dependency Injection (DI): It exposes the HttpClient class as a DI-ready type, making it easy to inject into your services.&lt;br&gt;
Logical Client Instances: You can configure and name logical HttpClient instances centrally. This helps manage different clients for various APIs or services.&lt;br&gt;
Middleware via Delegating Handlers: IHttpClientFactory codifies the concept of outgoing middleware using delegating handlers in HttpClient. These handlers allow you to add custom logic (such as authentication, logging, or retries) to your HTTP requests.&lt;br&gt;
Caching and Lifetime Management: It automatically manages the caching and lifetime of underlying HttpClientHandler instances.&lt;br&gt;
Logging: You get a configurable logging experience (via ILogger) for all requests sent through clients created by the factory.&lt;br&gt;
Consumption Patterns:&lt;br&gt;
There are several ways to use IHttpClientFactory in your app:&lt;br&gt;
Basic Usage: Register the factory by calling services.AddHttpClient() in your Startup.cs (or wherever you define your dependencies). Then, simply inject IHttpClientFactory into your classes where you need an HttpClient.&lt;br&gt;
Named Clients: You can create named clients for specific APIs or services. For example:&lt;br&gt;
C#&lt;/p&gt;

&lt;p&gt;services.AddHttpClient("GitHubClient", config =&amp;gt;&lt;br&gt;
{&lt;br&gt;
    config.BaseAddress = new Uri("&lt;a href="https://api.github.com/%22"&gt;https://api.github.com/"&lt;/a&gt;);&lt;br&gt;
});&lt;br&gt;
AI-generated code. Review and use carefully. More info on FAQ.&lt;br&gt;
Typed Clients: Define a typed client interface and implementation, and then register it with IHttpClientFactory. This allows you to inject a strongly-typed client into your services.&lt;br&gt;
Generated Clients: You can generate clients dynamically based on your needs.&lt;br&gt;
Important Note:&lt;br&gt;
If your app requires cookies, consider alternative ways of managing clients, as IHttpClientFactory might not be the best fit.&lt;br&gt;
For more detailed information and examples, you can refer to the official documentation on Using IHttpClientFactory and Make HTTP requests using IHttpClientFactory in ASP.NET Core. Happy coding! 🚀👨‍💻1234&lt;/p&gt;

</description>
      <category>httpclient</category>
      <category>cshap</category>
      <category>dotnetcore</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Wrapper classes in C#</title>
      <dc:creator>Shivanshu Sharma</dc:creator>
      <pubDate>Tue, 07 May 2024 16:48:26 +0000</pubDate>
      <link>https://dev.to/shivanshushady/wrapper-classes-in-c-jcl</link>
      <guid>https://dev.to/shivanshushady/wrapper-classes-in-c-jcl</guid>
      <description>&lt;p&gt;Let’s dive into the concept of wrapper classes in C#.&lt;/p&gt;

&lt;p&gt;A wrapper class is any class that “wraps” or “encapsulates” the functionality of another class or component. These wrapper classes are useful because they provide a level of abstraction from the implementation details of the underlying class or component1. In other words, they allow you to interact with the wrapped class in a more convenient and controlled manner.&lt;/p&gt;

&lt;p&gt;Here’s a simple example to illustrate the concept of a wrapper class:&lt;/p&gt;

&lt;p&gt;Suppose we have two classes: TaxCalculator and SalaryCalculator. The TaxCalculator class contains methods to calculate taxes, while the SalaryCalculator class is responsible for calculating salaries. We want to use the tax calculation functionality from TaxCalculator within the SalaryCalculator class without exposing the details of how taxes are calculated.&lt;/p&gt;

&lt;p&gt;Let’s create a wrapper class called Wrapper that encapsulates the TaxCalculator functionality:&lt;/p&gt;

&lt;p&gt;C#&lt;/p&gt;

&lt;p&gt;**_using System;&lt;/p&gt;

&lt;p&gt;namespace WrapperExample&lt;br&gt;
{&lt;br&gt;
    class TaxCalculator&lt;br&gt;
    {&lt;br&gt;
        public int CalculateTax(int salary)&lt;br&gt;
        {&lt;br&gt;
            // Implementation details for tax calculation&lt;br&gt;
            // ...&lt;br&gt;
            return taxAmount;&lt;br&gt;
        }&lt;br&gt;
    }&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Wrapper
{
    private TaxCalculator taxCalculator = new TaxCalculator();

    public int CalculateSalaryWithTax(int salary)
    {
        // Wrapping the tax calculation functionality
        int taxAmount = taxCalculator.CalculateTax(salary);
        return salary - taxAmount;
    }
}

class Program
{
    static void Main(string[] args)
    {
        Wrapper salaryWrapper = new Wrapper();
        int salary = 1000;
        int netSalary = salaryWrapper.CalculateSalaryWithTax(salary);_**

        Console.WriteLine($"Net salary after tax: {netSalary}");
        Console.ReadLine();
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;br&gt;
In this example:&lt;/p&gt;

&lt;p&gt;The Wrapper class encapsulates the TaxCalculator functionality by creating an instance of TaxCalculator internally.&lt;br&gt;
The CalculateSalaryWithTax method in the Wrapper class calculates the net salary after deducting taxes.&lt;br&gt;
By using the Wrapper class, we achieve two important goals:&lt;/p&gt;

&lt;p&gt;We hide the details of tax calculation from the SalaryCalculator class.&lt;br&gt;
We provide a cleaner and more abstract interface for calculating salaries.&lt;br&gt;
Remember that wrapper classes can be used in various scenarios, not just for tax calculations. Whenever you need to encapsulate functionality from another class or component, consider using a wrapper class to improve code organization and maintainability.&lt;/p&gt;

&lt;p&gt;I hope this helps you understand the concept of wrapper classes in C#! If you have any further questions, feel free to ask. 😊👍&lt;/p&gt;

</description>
      <category>csharp</category>
      <category>development</category>
      <category>webdev</category>
      <category>codenewbie</category>
    </item>
  </channel>
</rss>
