.NET
Filter by Set
...see more

Design patterns are reusable solutions to common problems in software design and factory design pattern is one of the common design patterns.

The Factory method is a creational design pattern that provides an interface for creating objects without specifying their concrete classes. It defines a method that we can use to create an object instead of using its constructor. The important thing is that the subclasses can override this method and create objects of different types.

Resources

...see more

The Task asynchronous programming model (TAP) provides an abstraction over asynchronous code. You write code as a sequence of statements, just like always. You can read that code as though each statement completes before the next begins. The compiler performs many transformations because some of those statements may start work and return a Task representing the ongoing work.

...see more

In .NET, when you assign one list (list2) to another list (list1) directly, both lists will reference the same memory location. As a result, any modifications made to list2 will also affect list1. To create a separate copy of the list, you should use the List<T> constructor to initialize a new list based on the elements of the original list (list1).

...see more

To illustrate the issue the following code assigns list1 directly to list2.

List<string> list1 = new List<string>();
List<string> list2 = list1;

list2.Add("Item A");

Console.WriteLine("List1 elements:");
list1.ForEach(item => Console.WriteLine(item));

This will output the list1 elements and show 'Item A'.

List1 elements:
Item A

As you can see, modifying list2 also modified list1.

Explanation of direct assignment issue

When you assign one list to another using list2 = list1, you're not creating a new list. Instead, both list1 and list2 will point to the same list in memory. Any changes made to one list will be reflected in the other because they are essentially the same list.

...see more

The following code shows modifying of list2 does not affect list1 because list2 is a separate copy of list1.

List<string> list1 = new List<string>();
List<string> list2 = new List<string>(list1);

list2.Add("Item A");

Console.WriteLine("List1 elements:");
list1.ForEach(item => Console.WriteLine(item));

This will output list1 without any item.

List1 elements:

Explanation of copying the List

You can use the List<T> constructor with the original list as an argument to create a new list that is a separate copy of the original list. This constructor creates a new list with the same elements as the original list.

...see more

.NET APIs include classes, interfaces, delegates, and value types that expedite and optimize the development process and provide access to system functionality.

.NET types use a dot syntax naming scheme that connotes a hierarchy. This technique groups related types into namespaces, which can be searched and referenced more easily. The first part of the full name—up to the rightmost dot—is the namespace name.

The System namespace is the root namespace for fundamental types in .NET. This namespace includes classes representing the base data types used by all applications.

.NET includes a set of data structures that are the workhorses of many .NET apps. These are mostly collections, but also include other types.

.NET includes a set of utility APIs that provide functionality for many important tasks.

There are many app models that can be used with .NET.

Further reading at .NET class library overview - .NET | Microsoft Learn.

...see more

URI stands for Uniform Resource Identifier. A URI is a string of characters that identifies a particular resource. Resources can be anything with an identity, such as a document, image, service, or concept. URIs are used to uniquely identify and locate resources on the internet or within a network.

...see more

URIs are categorized into two main types: URLs (Uniform Resource Locators) and URNs (Uniform Resource Names).

URL (Uniform Resource Locator)

  • A URL is a type of URI that specifies the location of a resource on the internet or a network.
  • It typically consists of several components, including the scheme (e.g., "http" or "https"), the host (domain name or IP address), and the path to the resource.
  • Example: https://www.example.com/path/to/resource

URN (Uniform Resource Name)

  • A URN is a type of URI used to identify a resource by name in a particular namespace uniquely.
  • Unlike URLs, URNs are meant to identify resources even if their location changes persistently.
  • Example: urn:isbn:0451450523
...see more

In .NET, the System.Uri class is used to represent URIs. You can create a Uri object by passing a URI string to its constructor. The Uri class provides various properties and methods for working with different components of the URI, such as the scheme, host, path, query, and fragment.

Here's a simple example in C#:

// Creating a Uri object
Uri uri = new Uri("https://www.example.com/path/to/resource");

// Accessing components of the URI
Console.WriteLine($"Scheme: {uri.Scheme}");
Console.WriteLine($"Host: {uri.Host}");
Console.WriteLine($"Path: {uri.AbsolutePath}");
Console.WriteLine($"Query: {uri.Query}");

This example demonstrates creating a Uri object from a URL string and accessing different components of the URI using properties like Scheme, Host, AbsolutePath, and Query.

...see more

OriginalString and AbsoluteUri have different behaviors.

AbsoluteUri does escaping

Uri uri = new Uri("http://www.example.com/test.aspx?v=hello world");

Console.WriteLine(uri.OriginalString);
// http://www.example.com/test.aspx?v=hello world

Console.WriteLine(uri.AbsoluteUri);
// http://www.example.com/test.aspx?v=hello%20world  <--  different

AbsoluteUri doesn't support relative URIs

var uri = new Uri("/test.aspx?v=hello world", UriKind.Relative);

Console.WriteLine(uri.OriginalString);
// /test.aspx?v=hello world

Console.WriteLine(uri.AbsoluteUri);
// InvalidOperationException: This operation is not supported for a relative URI.
...see more

In C#, you can replace multiple white spaces with a single white space using regular expressions. You can use the Regex class from the System.Text.RegularExpressions namespace to achieve this. Here's an example:

using System;
using System.Text.RegularExpressions;

class Program
{
    static void Main()
    {
        string inputString = "This   is   a    sample    string   with   multiple   spaces.";

        // Use regular expression to replace multiple white spaces with a single white space
        string result = Regex.Replace(inputString, @"\s+", " ");

        Console.WriteLine("Original string: " + inputString);
        Console.WriteLine("Modified string: " + result);
    }
}

In this example, the \s+ regular expression pattern matches one or more white spaces, and the Regex.Replace method replaces these occurrences with a single white space.

Additional Resources

...see more

The C# Retry Pattern is a coding strategy that enhances fault tolerance by automatically reattempting failed operations. Employing this pattern involves defining retry logic, such as delays between attempts, to improve the robustness and reliability of code handling transient errors.

Further Resources

...see more

This example in C# illustrates an implementation of the Retry pattern. The purpose of this method is to repeatedly attempt to execute a piece of code (referred to as the "main logic") until either the operation is successful or a specified number of retries has been reached.

public async Task RetryAsync()
{
  int retryCount = 3;
  int currentRetry = 0;

  for (;;)
  {
    try
    {
      // main logic here

      break; // Return or break.
    }
    catch (Exception ex)
    {
      currentRetry++;

      if (currentRetry > this.retryCount) throw;
    }

    await Task.Delay(TimeSpan.FromSeconds(5));
  }
}

Breakdown of the code:

  1. Initialization
  2. Infinite Loop (for (;;))
    • The method enters an infinite loop using a for loop without a condition, meaning it will continue indefinitely until explicitly broken out of.
    • Inside the loop:
      • If the main logic succeeds, the break statement is encountered, and the loop is exited.
      • If an exception occurs during the main logic execution (catch (Exception ex)), the catch block is executed.
  3. Handling Exceptions
    • currentRetry++;: Increments the currentRetry counter each time an exception is caught.
    • Checks whether the number of retries (currentRetry) has exceeded the maximum allowed retries (retryCount).
      • If the maximum retries have been reached, the exception is rethrown using throw;, propagating it further.
      • If the maximum retries have not been reached, the method proceeds to the next iteration after a delay.
  4. Delay Between Retries
...see more

The Task class is a key component of the Task Parallel Library, providing a framework for asynchronous programming. It represents a unit of work that can run concurrently with other tasks, offering efficient and scalable execution. Programmers use it to create, manage, and coordinate asynchronous operations, enhancing application responsiveness.

Namespace: System.Threading.Tasks

...see more

The Task.Delay Method creates a task that will complete after a time delay.

  • Task.Delay is generally preferred when working with asynchronous programming using async and await.
  • It returns a Task that represents a time delay.
  • It doesn't block the calling thread. Instead, it allows the thread to be released and continue with other work while waiting for the specified time to elapse.
  • It's more suitable for scenarios where you want to introduce a delay without blocking the execution of the current method or freezing the user interface in GUI applications.

Example:

async Task MyMethod()
{
    // Do something before the delay
    await Task.Delay(1000); // Delay for 1000 milliseconds (1 second)
    // Do something after the delay
}
...see more

The Thread class allows programmers to create and manage multithreaded applications. It enables concurrent code execution, allowing tasks to run independently for improved performance. Developers can utilize methods like Start, Join, and Sleep to control thread execution, facilitating efficient parallel processing in .NET applications.

Namespace: System.Threading

...see more

The Thread.Sleep Method Suspends the current thread for the specified amount of time.

  • Thread.Sleep is a synchronous method that blocks the current thread for the specified amount of time.
  • It's generally used in non-async scenarios or when dealing with multi-threading where you explicitly want to pause the execution of the current thread.
  • It can introduce responsiveness issues, especially in GUI applications, as it will freeze the UI during the sleep period.

Example:

void MyMethod()
{
    // Do something before the delay
    Thread.Sleep(1000); // Sleep for 1000 milliseconds (1 second)
    // Do something after the delay
}
Add to Set
  • .NET
  • .NET 6.0 Migration
  • 5 Best websites to read books online free with no downloads
  • 5 surprising things that men find unattractive
  • 5 Ways To Take Control of Overthinking
  • 6 simple methods for a more productive workday
  • 6 Ways To Stop Stressing About Things You Can't Control
  • Add React to ASP.NET Core
  • Adding reCAPTCHA to a .NET Core Web Site
  • Admin Accounts
  • Adobe Acrobat
  • Afraid of the new job? 7 positive tips against negative feelings
  • Agile
  • AKS and Kubernetes Commands (kubectl)
  • API Lifecycle Management
  • arc42
  • Article Writing Tools
  • Atlassian
  • Azure API Management
  • Azure App Registration
  • Azure Application Gateway
  • Azure Arc
  • Azure Arc Commands
  • Azure Architectures
  • Azure Bastion
  • Azure Bicep
  • Azure CLI Commands
  • Azure Cloud Products
  • Azure Cognitive Services
  • Azure Container Apps
  • Azure Cosmos DB
  • Azure Cosmos DB Commands
  • Azure Costs
  • Azure Daily
  • Azure Daily 2022
  • Azure Daily 2023
  • Azure Data Factory
  • Azure Database for MySQL
  • Azure Databricks
  • Azure Diagram Samples
  • Azure Durable Functions
  • Azure Firewall
  • Azure Functions
  • Azure Kubernetes Service (AKS)
  • Azure Landing Zone
  • Azure Log Analytics
  • Azure Logic Apps
  • Azure Maps
  • Azure Monitor
  • Azure News
  • Azure PowerShell Cmdlets
  • Azure PowerShell Login
  • Azure Private Link
  • Azure Purview
  • Azure Redis Cache
  • Azure Security Groups
  • Azure Sentinel
  • Azure Service Bus
  • Azure Service Bus Questions (FAQ)
  • Azure Services Abstract
  • Azure SQL
  • Azure Tips and Tricks
  • Backlog Items
  • BASH Programming
  • Best LinkedIn Tips (Demo Test)
  • Best Practices for RESTful API
  • Bing Maps
  • Birthday Gift Ideas for Wife
  • Birthday Poems
  • Black Backgrounds and Wallpapers
  • Bootstrap Templates
  • Brave New World
  • Brian Tracy Quotes
  • Build Websites Resources
  • C# Development Issues
  • C# Programming Guide
  • Caching
  • Caching Patterns
  • Camping Trip Checklist
  • Canary Deployment
  • Careers of the Future You Should Know About
  • Cheap Vacation Ideas
  • Cloud Computing
  • Cloud Migration Methods
  • Cloud Native Applications
  • Cloud Service Models
  • Cloudflare
  • Code Snippets
  • Compelling Reasons Why Money Can’t Buy Happiness
  • Conditional Access
  • Configurations for Application Insights
  • Create a Routine
  • Create sitemap.xml in ASP.NET Core
  • Creative Writing: Exercises for creative texts
  • CSS Selectors Cheat Sheet
  • Cultivate a Growth Mindset
  • Cultivate a Growth Mindset by Stealing From Silicon Valley
  • Custom Script Extension for Windows
  • Daily Scrum (Meeting)
  • Dalai Lama Quotes
  • DataGridView
  • Decision Trees
  • Deployments in Azure
  • Dev Box
  • Development Flows
  • Docker
  • Don’t End a Meeting Without Doing These 3 Things
  • Drink More Water: This is How it Works
  • Dropdown Filter
  • Earl Nightingale Quotes
  • Easy Steps Towards Energy Efficiency
  • EF Core
  • Elon Musk
  • Elon Musk Companies
  • Employment
  • English
  • Escape Double Quotes in C#
  • Escaping characters in C#
  • Executing Raw SQL Queries using Entity Framework Core
  • Factors to Consider While Selecting the Best Earthmoving System
  • Feng Shui 101: How to Harmonize Your Home in the New Year
  • Flying Machines
  • Foods against cravings
  • Foods that cool you from the inside
  • Four Misconceptions About Drinking
  • Fox News
  • Free APIs
  • Funny Life Quotes
  • Generate Faces
  • Generate Random Numbers in C#
  • Genius Money Hacks for Massive Savings
  • GitHub
  • GitHub Concepts
  • Green Careers Set to Grow in the Next Decade
  • Habits Of Highly Stressed People and how to avoid them
  • Happy Birthday Wishes & Quotes
  • Helm Overview
  • How to Clean Floors – Tips & Tricks
  • How to invest during the 2021 pandemic
  • How To Make Money From Real Estate
  • How To Stop Drinking Coffee
  • Image for Websites
  • Inspirational Quotes
  • Iqra Technology, IT Services provider Company
  • Jobs Of 2050
  • jQuery
  • jQuery plugins
  • JSON for Linking Data (JSON-LD)
  • Json to C# Converters
  • Karen Lamb Quotes
  • Kubernetes Objects
  • Kubernetes Tools
  • Kusto Query Language
  • Lack of time at work? 5 simple tricks to help you avoid stress
  • Lambda (C#)
  • Last Minute Travel Tips
  • Last-Minute-Reisetipps
  • Latest Robotics
  • Leadership
  • List Of Hobbies And Interests
  • Logitech BRIO Webcam
  • Management
  • Mark Twain Quotes
  • Markdown
  • Meet Sophia
  • Message-Oriented Architecture
  • Microservices
  • Microsoft Authenticator App
  • Microsoft Power Automate
  • Microsoft SQL Server
  • Microsoft Teams
  • Mobile UI Frameworks
  • Motivation
  • Multilingual Applications
  • NBC News
  • NuGet
  • Objectives and Key Results (OKR)
  • Objectives and Key Results (OKR) Samples
  • OKR Software
  • Online JSON Viewer and Parser
  • Outlook Automation
  • PCMag
  • Phases of any relationship
  • Playwright
  • Popular cars per decade
  • Popular Quotes
  • PowerShell
  • PowerShell Array Guide
  • PowerShell Coding Samples
  • PowerToys
  • Prism
  • Pros & Cons Of Alternative Energy
  • Quill Rich Text Editor
  • Quotes
  • RACI Matrix
  • Razor Syntax
  • Reasons why singletasking is better than multitasking
  • Regular Expression (RegEx)
  • Resize Images in C#
  • RESTful APIs
  • Rich Text Editors
  • Rob Siltanen Quotes
  • Robots
  • Run sudo commands
  • Salesforce Offshore Support Services Providers
  • Sample Data
  • Save Money On Food
  • Score with authenticity in the job interview
  • Security
  • Semantic Versioning
  • Serialization using Thread Synchronization
  • Service Worker
  • Snipps
  • Speak and Presentation
  • SQL References
  • SQL Server Full-Text Search
  • Successful
  • Surface Lineup 2021
  • Surface Lineup 2021 Videos
  • SVG Online Editors
  • Team Manifesto
  • Technologies
  • Technology Abbreviations
  • Technology Glossary
  • TechSpot
  • That is why you should drink cucumber water every day
  • The Cache Tag Helper in ASP.NET Core
  • The Verge
  • Theodore Roosevelt Quotes
  • These 7 things make you unattractive
  • Things Successful People Do That Others Don’t
  • Things to Consider for a Great Birthday Party
  • Things to Consider When Designing A Website
  • Thoughts
  • TinyMCE Image Options
  • TinyMCE Toolbar Options
  • Tips for a Joyful Life
  • Tips for fewer emails at work
  • Tips for Making Better Decisions
  • Tips for Managing the Stress of Working at Home
  • Tips for Writing that Great Blog Post
  • Tips On Giving Flowers As Gifts
  • Tips you will listen better
  • Top Fitness Tips
  • Top Healthy Tips
  • Top Money Tips
  • Top Ten Jobs
  • Track Authenticated Users in Application Insights
  • Unicode Characters
  • Visual Studio 2022
  • Vital everyday work: tips for healthy work
  • Walking barefoot strengthens your immune system
  • Walt Disney Quotes
  • Ways for Kids to Make Money
  • Web Design Trends & Ideas
  • Web Icons
  • Web Scraping
  • Webhooks
  • Website Feature Development
  • What are my options for investing money?
  • What happens when you drink water in the morning
  • What Is Stressful About Working at Home
  • What To Eat For Lunch
  • Windows 11 Top Features You Should Know
  • Winston Churchill Quotes
  • XPath
  • You'll burn out your team with these 5 leadership mistakes
  • ZDNet
 
Sets