Posts

Showing posts from November, 2024

C# IEnumerable vs IEnumerator

IEnumerable vs. IEnumerator  IEnumerable vs. IEnumerator Both are uses to loop through lists.  'For each' uses internally getEnumerator() to iterating to objects.  Differences: - IEnumerable uses IEnumerator internally.  IEnumerable does not remember its cursor position where as IEnumerator remembers it.  For example you are writing two functions to list some details , one should list the years less than 2000 and other function should show the years greater than 2000.  I Enumerator will support it by keeping its current cursor position (current state).   Example:- List Year = new List ();  Year.Add(2000);  Year.Add(2001);  Year.Add(2002);  IEnumerable getYear = (IEnumerable )Year;  foreach (int i in getYear) { txtYeas.Text += i.ToString() + ","; }  IEnumerator getsYear = Year.GetEnumerator();  while (getsYear.MoveNext()) { txtYeas.Text += getsYear.Current.ToString() + ","; }  IComparable vs. IComparer Use...

Delegates and Multicast Delegate in C#

  Delegate and Multicast Delegate  A delegate is a reference type variable that holds the reference to a method. The reference can be changed at runtime. Key Points about Delegates: Type-Safe Method References : A delegate is type-safe, meaning it can only reference methods that match its signature (i.e., return type and parameters). Encapsulating Methods : A delegate can reference a single method or multiple methods (multicast delegates). When a delegate is invoked, it calls the method(s) it references. Delegates and Events : Delegates are often used in C# for events and callback mechanisms. Events in C# are built upon delegates. All delegates are implicitly derived from the System.Delegate class Creating Delegates, You can declare a delegate type and then instantiate it to reference methods that match its signature. // Declare a delegate type public delegate void MyDelegate(string message); Create Methods that Match the Delegate's Signature : public class ExampleClass { ...

How to scaffold an existing SQL Server database using Entity Framework Core (EF Core) C#

         How to scaffold an existing SQL Server database using Entity Framework Core To scaffold an existing SQL Server database using Entity Framework Core (EF Core) in a Database-First approach, you can use the Scaffold-DbContext command in the Package Manager Console or dotnet CLI. This process will generate the entity models and the DbContext class based on your existing database schema. Prerequisites Install .NET SDK: Make sure you have the .NET SDK installed on your machine. Install Entity Framework Core Tools: Ensure that your project has EF Core and related packages.  Step 1: Install EF Core NuGet Packages  In the Package Manager Console (in Visual Studio): Install-Package Microsoft.EntityFrameworkCore.SqlServer Install-Package Microsoft.EntityFrameworkCore.Tools Step 2: Scaffold the Database Using Package Manager Console Open Package Manager Console in Visual Studio ( Tools > NuGet Package Manager > Package Manager Console ). Ru...

What is variable Hiding? When you have a variable with the same name in both a base class and a derived class which value is hiding?

In C#, when you have a variable with the same name in both a base class and a derived class, this concept is known as variable hiding (not to be confused with method overriding).  When you access that variable from an instance of the derived class, the variable from the derived class hides the one from the base class.  That's why the value from the base class might not be visible. Let's break down how this works and why you see only the value from the child class.   Example Code: V ariable Hiding in C#   using System;   public class BaseClass  {   public string Name = "BaseClass";   public void ShowBaseName()   {   Console.WriteLine($"Base class Name: {Name}");   }  }   public class ChildClass : BaseClass  {   public string Name = "ChildClass"; public void ShowChildName()   {   Console.WriteLine($"Child class Name: {Name}");   }...

IIS Architecture , A history

Image
IIS Architecture IIS (Internet Information Server) is one of the most powerful web servers from Microsoft that is used to host your ASP.NET Web application. IIS has it's own ASP.NET Process Engine to handle the ASP.NET request. So, when a request comes from client to server, IIS takes that request and process it and send response back to clients. Request Processing : Now let’s have a look how they do things internally. Before we move ahead, you have to know about two main concepts  1.   WorkerProcess 2.    Application Pool Worker Process:    Worker Process ( w3wp.exe ) runs the ASP.Net application in IIS. This process is responsible to manage all the request and response that are coming from client system.  All the ASP.Net functionality runs under the scope of worker process.   When a request comes to the server from a client worker process is responsible to generate the request and response.  In a single w...