<?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: DIVAKAR UPADHYAY</title>
    <description>The latest articles on DEV Community by DIVAKAR UPADHYAY (@divakarupadhyay).</description>
    <link>https://dev.to/divakarupadhyay</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4233058%2Fadd51220-4d28-4371-b9d7-605e01d452f1.jpg</url>
      <title>DEV Community: DIVAKAR UPADHYAY</title>
      <link>https://dev.to/divakarupadhyay</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/divakarupadhyay"/>
    <language>en</language>
    <item>
      <title>Core objects and the connected model — ADO.NET</title>
      <dc:creator>DIVAKAR UPADHYAY</dc:creator>
      <pubDate>Sun, 08 Nov 2026 06:12:34 +0000</pubDate>
      <link>https://dev.to/divakarupadhyay/core-objects-and-the-connected-model-adonet-2jff</link>
      <guid>https://dev.to/divakarupadhyay/core-objects-and-the-connected-model-adonet-2jff</guid>
      <description>&lt;p&gt;&lt;em&gt;Lesson 1 of 9 in the free &lt;a href="https://devladder.pages.dev/courses/adonet" rel="noopener noreferrer"&gt;ADO.NET — Connected &amp;amp; Disconnected Data Access&lt;/a&gt; course on DevLadder.&lt;/em&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Object&lt;/th&gt;
&lt;th&gt;Role&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;SqlConnection&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Connection to the DB (pooled)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;SqlCommand&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;SQL statement or stored procedure&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;SqlParameter&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Typed parameter value — prevents SQL injection&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;SqlDataReader&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Fast, forward-only, read-only stream of rows&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;SqlDataAdapter&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Bridge between DB and &lt;code&gt;DataSet&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;DataSet&lt;/code&gt; / &lt;code&gt;DataTable&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;In-memory relational data&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;SqlTransaction&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Groups commands atomically&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;SqlBulkCopy&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;High-speed bulk insert&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;cs&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Server=.;Database=Shop;Integrated Security=True;TrustServerCertificate=True"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;var&lt;/span&gt; &lt;span class="n"&gt;conn&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;SqlConnection&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cs&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;conn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;OpenAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ct&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;var&lt;/span&gt; &lt;span class="n"&gt;cmd&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;SqlCommand&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"SELECT Id, Name, Price FROM Products WHERE CategoryId = @cat"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;conn&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="n"&gt;cmd&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Parameters&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"@cat"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;SqlDbType&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Int&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;Value&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;categoryId&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;var&lt;/span&gt; &lt;span class="n"&gt;reader&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;cmd&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ExecuteReaderAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ct&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;list&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;List&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Product&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;();&lt;/span&gt;
&lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;reader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ReadAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ct&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;list&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;Product&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;reader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;GetInt32&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="n"&gt;reader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;GetString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="n"&gt;reader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;GetDecimal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)));&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use ordinal getters (&lt;code&gt;GetInt32(0)&lt;/code&gt;) or cache &lt;code&gt;reader.GetOrdinal("Name")&lt;/code&gt; for speed; check &lt;code&gt;reader.IsDBNull(i)&lt;/code&gt; before reading nullable columns.&lt;/p&gt;

&lt;h2&gt;
  
  
  Interview questions on ADO.NET
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What is ADO.NET? Name its main objects.
&lt;/h3&gt;

&lt;p&gt;ADO.NET is .NET's core data access library (&lt;code&gt;System.Data&lt;/code&gt; + provider packages). Main objects: &lt;code&gt;Connection&lt;/code&gt; (connects to the DB), &lt;code&gt;Command&lt;/code&gt; (executes SQL/procs), &lt;code&gt;Parameter&lt;/code&gt;, &lt;code&gt;DataReader&lt;/code&gt; (forward-only fast read), &lt;code&gt;DataAdapter&lt;/code&gt; (fills/updates DataSets), &lt;code&gt;DataSet&lt;/code&gt;/&lt;code&gt;DataTable&lt;/code&gt; (in-memory data), &lt;code&gt;Transaction&lt;/code&gt;. For SQL Server use &lt;code&gt;Microsoft.Data.SqlClient&lt;/code&gt; (&lt;code&gt;SqlConnection&lt;/code&gt;, &lt;code&gt;SqlCommand&lt;/code&gt;...).&lt;/p&gt;

&lt;h3&gt;
  
  
  What is the difference between connected and disconnected architecture?
&lt;/h3&gt;

&lt;p&gt;Connected: the connection stays open while you read with a &lt;code&gt;DataReader&lt;/code&gt; — forward-only, read-only, very fast, minimal memory. Disconnected: a &lt;code&gt;DataAdapter&lt;/code&gt; fills a &lt;code&gt;DataSet&lt;/code&gt;/&lt;code&gt;DataTable&lt;/code&gt;, then closes the connection; you can navigate, edit and later push changes back with &lt;code&gt;Update()&lt;/code&gt; — more memory, more flexibility. Modern apps mostly use the connected model (directly or via Dapper/EF).&lt;/p&gt;

&lt;h3&gt;
  
  
  What is the difference between ExecuteReader, ExecuteScalar and ExecuteNonQuery?
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;ExecuteReader&lt;/code&gt; returns a &lt;code&gt;DataReader&lt;/code&gt; for one or more result sets. &lt;code&gt;ExecuteScalar&lt;/code&gt; returns the first column of the first row (COUNT, SUM, new identity via &lt;code&gt;OUTPUT&lt;/code&gt;/&lt;code&gt;SCOPE_IDENTITY()&lt;/code&gt;). &lt;code&gt;ExecuteNonQuery&lt;/code&gt; runs INSERT/UPDATE/DELETE/DDL and returns the number of rows affected (-1 for statements that don't affect rows, or when &lt;code&gt;SET NOCOUNT ON&lt;/code&gt; is set).&lt;/p&gt;




&lt;p&gt;Read the &lt;a href="https://devladder.pages.dev/courses/adonet/lessons/core-objects-and-the-connected-model" rel="noopener noreferrer"&gt;full lesson with progress tracking&lt;/a&gt; and the rest of the course on &lt;strong&gt;DevLadder&lt;/strong&gt; — free step-by-step tutorials and interview questions for developers.&lt;/p&gt;

&lt;p&gt;Next in the course: &lt;a href="https://devladder.pages.dev/courses/adonet/lessons/executereader-vs-executescalar-vs-executenonquery" rel="noopener noreferrer"&gt;ExecuteReader vs ExecuteScalar vs ExecuteNonQuery&lt;/a&gt; →&lt;/p&gt;

</description>
      <category>dotnet</category>
      <category>csharp</category>
      <category>beginners</category>
      <category>interview</category>
    </item>
    <item>
      <title>Singleton — Design Patterns (GoF + Enterprise) in C#</title>
      <dc:creator>DIVAKAR UPADHYAY</dc:creator>
      <pubDate>Sun, 08 Nov 2026 06:11:14 +0000</pubDate>
      <link>https://dev.to/divakarupadhyay/singleton-design-patterns-gof-enterprise-in-c-1bnp</link>
      <guid>https://dev.to/divakarupadhyay/singleton-design-patterns-gof-enterprise-in-c-1bnp</guid>
      <description>&lt;p&gt;&lt;em&gt;Lesson 1 of 18 in the free &lt;a href="https://devladder.pages.dev/courses/design-patterns" rel="noopener noreferrer"&gt;Design Patterns (GoF + Enterprise) in C#&lt;/a&gt; course on DevLadder.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Ensure a class has &lt;strong&gt;one instance&lt;/strong&gt; with a global access point.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Thread-safe, lazy Singleton&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;sealed&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;AppConfig&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="n"&gt;Lazy&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;AppConfig&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;_instance&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;AppConfig&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="n"&gt;AppConfig&lt;/span&gt; &lt;span class="n"&gt;Instance&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;_instance&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nf"&gt;AppConfig&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="cm"&gt;/* load settings once */&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;ConnectionString&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;set&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;""&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Modern .NET: let the DI container own the lifetime instead&lt;/span&gt;
&lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Services&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;AddSingleton&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;IAppConfig&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;AppConfig&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Other thread-safe options: a &lt;code&gt;static readonly&lt;/code&gt; field (initialised by the CLR's type initialiser, thread-safe), or double-checked locking. Downsides of the hand-written pattern: global state, hidden dependencies, hard to test. Prefer &lt;code&gt;AddSingleton&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Interview questions on Design Patterns (GoF + Enterprise) in C
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What are design patterns? Name the three GoF categories.
&lt;/h3&gt;

&lt;p&gt;Reusable, named solutions to recurring design problems. GoF (1994) lists 23 in three categories: &lt;strong&gt;Creational&lt;/strong&gt; (Singleton, Factory Method, Abstract Factory, Builder, Prototype), &lt;strong&gt;Structural&lt;/strong&gt; (Adapter, Bridge, Composite, Decorator, Facade, Flyweight, Proxy), &lt;strong&gt;Behavioural&lt;/strong&gt; (Chain of Responsibility, Command, Interpreter, Iterator, Mediator, Memento, Observer, State, Strategy, Template Method, Visitor).&lt;/p&gt;

&lt;h3&gt;
  
  
  How do you implement a thread-safe Singleton in C#?
&lt;/h3&gt;

&lt;p&gt;Use &lt;code&gt;Lazy&amp;lt;T&amp;gt;&lt;/code&gt;: &lt;code&gt;private static readonly Lazy&amp;lt;Svc&amp;gt; _i = new(() =&amp;gt; new Svc()); public static Svc Instance =&amp;gt; _i.Value;&lt;/code&gt; with a private constructor and a &lt;code&gt;sealed&lt;/code&gt; class. &lt;code&gt;Lazy&amp;lt;T&amp;gt;&lt;/code&gt; is thread-safe by default (&lt;code&gt;ExecutionAndPublication&lt;/code&gt;). Alternatives: a &lt;code&gt;static readonly&lt;/code&gt; field (thread-safe because of the type initialiser), or double-checked locking with &lt;code&gt;volatile&lt;/code&gt;. In ASP.NET Core, prefer &lt;code&gt;services.AddSingleton&amp;lt;ISvc, Svc&amp;gt;()&lt;/code&gt;. It's testable and the container manages the lifetime.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is the difference between Factory Method and Abstract Factory?
&lt;/h3&gt;

&lt;p&gt;Factory Method creates &lt;strong&gt;one product&lt;/strong&gt;, and subclasses (or a method) decide which concrete class to create. Abstract Factory creates a &lt;strong&gt;family of related products&lt;/strong&gt; through an interface with several create methods (button + textbox for a theme; connection + command + parameter for a DB provider). Factory Method uses inheritance; Abstract Factory uses composition (you pass the factory object).&lt;/p&gt;




&lt;p&gt;Read the &lt;a href="https://devladder.pages.dev/courses/design-patterns/lessons/singleton" rel="noopener noreferrer"&gt;full lesson with progress tracking&lt;/a&gt; and the rest of the course on &lt;strong&gt;DevLadder&lt;/strong&gt; — free step-by-step tutorials and interview questions for developers.&lt;/p&gt;

&lt;p&gt;Next in the course: &lt;a href="https://devladder.pages.dev/courses/design-patterns/lessons/factory-method-and-simple-factory" rel="noopener noreferrer"&gt;Factory Method and Simple Factory&lt;/a&gt; →&lt;/p&gt;

</description>
      <category>dotnet</category>
      <category>csharp</category>
      <category>beginners</category>
      <category>interview</category>
    </item>
    <item>
      <title>S — Single Responsibility Principle — SOLID Principles with Examples</title>
      <dc:creator>DIVAKAR UPADHYAY</dc:creator>
      <pubDate>Sun, 08 Nov 2026 06:09:54 +0000</pubDate>
      <link>https://dev.to/divakarupadhyay/s-single-responsibility-principle-solid-principles-with-examples-1e88</link>
      <guid>https://dev.to/divakarupadhyay/s-single-responsibility-principle-solid-principles-with-examples-1e88</guid>
      <description>&lt;p&gt;&lt;em&gt;Lesson 1 of 8 in the free &lt;a href="https://devladder.pages.dev/courses/solid" rel="noopener noreferrer"&gt;SOLID Principles with Examples&lt;/a&gt; course on DevLadder.&lt;/em&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"A class should have one, and only one, reason to change." — Robert C. Martin&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;"Reason to change" = one &lt;strong&gt;actor&lt;/strong&gt; or stakeholder. A class that formats invoices &lt;em&gt;and&lt;/em&gt; saves them &lt;em&gt;and&lt;/em&gt; emails them changes when finance, DBAs or the email provider change.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="c1"&gt;// ❌ Violates SRP — three reasons to change&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;InvoiceService&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;decimal&lt;/span&gt; &lt;span class="nf"&gt;Calculate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Invoice&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Lines&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;l&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;l&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Qty&lt;/span&gt; &lt;span class="p"&gt;*&lt;/span&gt; &lt;span class="n"&gt;l&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Price&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;*&lt;/span&gt; &lt;span class="m"&gt;1.18m&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;Save&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Invoice&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;var&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;SqlConnection&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"..."&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="cm"&gt;/* INSERT ... */&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;Email&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Invoice&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;smtp&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;SmtpClient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"smtp.example.com"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="cm"&gt;/* ... */&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// ✅ One responsibility each&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;InvoiceCalculator&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;decimal&lt;/span&gt; &lt;span class="nf"&gt;Total&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Invoice&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Lines&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;l&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;l&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Qty&lt;/span&gt; &lt;span class="p"&gt;*&lt;/span&gt; &lt;span class="n"&gt;l&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Price&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;*&lt;/span&gt; &lt;span class="m"&gt;1.18m&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;interface&lt;/span&gt; &lt;span class="nc"&gt;IInvoiceRepository&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;Task&lt;/span&gt; &lt;span class="nf"&gt;SaveAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Invoice&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;interface&lt;/span&gt; &lt;span class="nc"&gt;IInvoiceSender&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;Task&lt;/span&gt; &lt;span class="nf"&gt;SendAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Invoice&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;InvoiceWorkflow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;InvoiceCalculator&lt;/span&gt; &lt;span class="n"&gt;calc&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;IInvoiceRepository&lt;/span&gt; &lt;span class="n"&gt;repo&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;IInvoiceSender&lt;/span&gt; &lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="n"&gt;Task&lt;/span&gt; &lt;span class="nf"&gt;CompleteAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Invoice&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Total&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;calc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Total&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;repo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;SaveAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;SendAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Interview tip:&lt;/strong&gt; SRP doesn't mean "one method per class". It means one &lt;em&gt;cohesive&lt;/em&gt; job. Controllers that only orchestrate are fine.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Interview questions on SOLID Principles with Examples
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What are the SOLID principles? Explain each briefly.
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;S&lt;/strong&gt;ingle Responsibility: one reason to change per class.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;O&lt;/strong&gt;pen/Closed: extend behaviour by adding code, not modifying existing code.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;L&lt;/strong&gt;iskov Substitution: subclasses must work anywhere the base class works.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;I&lt;/strong&gt;nterface Segregation: small client-specific interfaces instead of a fat one.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;D&lt;/strong&gt;ependency Inversion: high- and low-level modules depend on abstractions; inject dependencies.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Follow with one concrete example from your own project, e.g. "payment providers behind &lt;code&gt;IPaymentGateway&lt;/code&gt;, registered in DI — that's OCP and DIP."&lt;/p&gt;

&lt;h3&gt;
  
  
  Give a real example of the Single Responsibility Principle.
&lt;/h3&gt;

&lt;p&gt;An &lt;code&gt;InvoiceService&lt;/code&gt; that calculates totals, writes to SQL and sends email has three reasons to change. Split it into &lt;code&gt;InvoiceCalculator&lt;/code&gt;, &lt;code&gt;IInvoiceRepository&lt;/code&gt; and &lt;code&gt;IInvoiceSender&lt;/code&gt;, with a small workflow class orchestrating them. Now an SMTP-to-SendGrid change touches only the sender, and each part has focused unit tests.&lt;/p&gt;

&lt;h3&gt;
  
  
  How do you implement the Open/Closed Principle in C#?
&lt;/h3&gt;

&lt;p&gt;Through &lt;strong&gt;abstractions and polymorphism&lt;/strong&gt;: define an interface (&lt;code&gt;IDiscountRule&lt;/code&gt;, &lt;code&gt;IExportFormatter&lt;/code&gt;), implement each variant as its own class, and let the consumer receive &lt;code&gt;IEnumerable&amp;lt;IDiscountRule&amp;gt;&lt;/code&gt; from DI. Adding a variant means a new class and registration; no existing, tested code changes. Other OCP tools: Strategy, Decorator, middleware, filters, events.&lt;/p&gt;




&lt;p&gt;Read the &lt;a href="https://devladder.pages.dev/courses/solid/lessons/s-single-responsibility-principle" rel="noopener noreferrer"&gt;full lesson with progress tracking&lt;/a&gt; and the rest of the course on &lt;strong&gt;DevLadder&lt;/strong&gt; — free step-by-step tutorials and interview questions for developers.&lt;/p&gt;

&lt;p&gt;Next in the course: &lt;a href="https://devladder.pages.dev/courses/solid/lessons/o-open-closed-principle" rel="noopener noreferrer"&gt;O — Open/Closed Principle&lt;/a&gt; →&lt;/p&gt;

</description>
      <category>dotnet</category>
      <category>csharp</category>
      <category>beginners</category>
      <category>interview</category>
    </item>
    <item>
      <title>Class, object, fields, properties and methods — OOP Concepts in C#</title>
      <dc:creator>DIVAKAR UPADHYAY</dc:creator>
      <pubDate>Sun, 08 Nov 2026 06:08:34 +0000</pubDate>
      <link>https://dev.to/divakarupadhyay/class-object-fields-properties-and-methods-oop-concepts-in-c-2lbi</link>
      <guid>https://dev.to/divakarupadhyay/class-object-fields-properties-and-methods-oop-concepts-in-c-2lbi</guid>
      <description>&lt;p&gt;&lt;em&gt;Lesson 1 of 15 in the free &lt;a href="https://devladder.pages.dev/courses/oop" rel="noopener noreferrer"&gt;OOP Concepts in C#&lt;/a&gt; course on DevLadder.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;A &lt;strong&gt;class&lt;/strong&gt; is a blueprint; an &lt;strong&gt;object&lt;/strong&gt; is an instance created from it at runtime.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;BankAccount&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;decimal&lt;/span&gt; &lt;span class="n"&gt;_balance&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;                       &lt;span class="c1"&gt;// field (state) — private&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;Owner&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;                    &lt;span class="c1"&gt;// read-only property&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;decimal&lt;/span&gt; &lt;span class="n"&gt;Balance&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;_balance&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;             &lt;span class="c1"&gt;// computed property&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;BankAccount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;owner&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;decimal&lt;/span&gt; &lt;span class="n"&gt;opening&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;   &lt;span class="c1"&gt;// constructor&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;Owner&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;owner&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;_balance&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;opening&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;Deposit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;decimal&lt;/span&gt; &lt;span class="n"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;             &lt;span class="c1"&gt;// method (behaviour)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;amount&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;ArgumentOutOfRangeException&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;nameof&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
        &lt;span class="n"&gt;_balance&lt;/span&gt; &lt;span class="p"&gt;+=&lt;/span&gt; &lt;span class="n"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;acc&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;BankAccount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Divakar"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;500&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;           &lt;span class="c1"&gt;// object&lt;/span&gt;
&lt;span class="n"&gt;acc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Deposit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;250&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;acc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Balance&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;                      &lt;span class="c1"&gt;// 750&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Interview questions on OOP Concepts in C
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What are the four pillars of OOP? Explain each with an example.
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Encapsulation&lt;/strong&gt; — private state with a controlled public API. &lt;code&gt;BankAccount&lt;/code&gt; keeps &lt;code&gt;_balance&lt;/code&gt; private and exposes &lt;code&gt;Deposit()&lt;/code&gt; that rejects negative amounts.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Abstraction&lt;/strong&gt; — expose &lt;em&gt;what&lt;/em&gt;, hide &lt;em&gt;how&lt;/em&gt;. &lt;code&gt;IPaymentGateway.ChargeAsync()&lt;/code&gt; hides HTTP calls, signatures and retries.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Inheritance&lt;/strong&gt; — a derived class reuses and extends a base. &lt;code&gt;Contractor : Employee&lt;/code&gt; reuses &lt;code&gt;Name&lt;/code&gt; and &lt;code&gt;Describe()&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Polymorphism&lt;/strong&gt; — the same call behaves differently by type. &lt;code&gt;employee.MonthlyPay()&lt;/code&gt; runs the &lt;code&gt;Permanent&lt;/code&gt; or &lt;code&gt;Contractor&lt;/code&gt; override at runtime.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  What is the difference between a class and an object?
&lt;/h3&gt;

&lt;p&gt;A class is a &lt;strong&gt;type definition&lt;/strong&gt; (blueprint) describing fields, properties and methods; it exists in code and metadata. An object is an &lt;strong&gt;instance&lt;/strong&gt; of that class created at runtime with &lt;code&gt;new&lt;/code&gt;, occupying memory with its own state. One class, many objects.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is the difference between method overloading and method overriding?
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Overloading&lt;/th&gt;
&lt;th&gt;Overriding&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Same name, &lt;strong&gt;different parameters&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;Same signature in a derived class&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Same class (or derived)&lt;/td&gt;
&lt;td&gt;Requires &lt;code&gt;virtual&lt;/code&gt;/&lt;code&gt;abstract&lt;/code&gt; + &lt;code&gt;override&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Resolved at &lt;strong&gt;compile time&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;Resolved at &lt;strong&gt;runtime&lt;/strong&gt; by the object's type&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Return type alone can't differ&lt;/td&gt;
&lt;td&gt;Return type the same (covariant returns allowed since C# 9)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;p&gt;Read the &lt;a href="https://devladder.pages.dev/courses/oop/lessons/class-object-fields-properties-and-methods" rel="noopener noreferrer"&gt;full lesson with progress tracking&lt;/a&gt; and the rest of the course on &lt;strong&gt;DevLadder&lt;/strong&gt; — free step-by-step tutorials and interview questions for developers.&lt;/p&gt;

&lt;p&gt;Next in the course: &lt;a href="https://devladder.pages.dev/courses/oop/lessons/constructors-default-parameterised-static-private-chaining" rel="noopener noreferrer"&gt;Constructors: default, parameterised, static, private, chaining&lt;/a&gt; →&lt;/p&gt;

</description>
      <category>dotnet</category>
      <category>csharp</category>
      <category>beginners</category>
      <category>interview</category>
    </item>
    <item>
      <title>.NET Framework vs .NET Core vs .NET 5+ — the history explained — .NET Internals</title>
      <dc:creator>DIVAKAR UPADHYAY</dc:creator>
      <pubDate>Sun, 08 Nov 2026 06:07:14 +0000</pubDate>
      <link>https://dev.to/divakarupadhyay/net-framework-vs-net-core-vs-net-5-the-history-explained-net-internals-776</link>
      <guid>https://dev.to/divakarupadhyay/net-framework-vs-net-core-vs-net-5-the-history-explained-net-internals-776</guid>
      <description>&lt;p&gt;&lt;em&gt;Lesson 1 of 11 in the free &lt;a href="https://devladder.pages.dev/courses/dotnet-internals" rel="noopener noreferrer"&gt;.NET Internals — CLR, CTS, CLS, IL, JIT, Memory Management &amp;amp; Garbage Collection&lt;/a&gt; course on DevLadder.&lt;/em&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;.NET Framework&lt;/th&gt;
&lt;th&gt;.NET Core 1–3.1&lt;/th&gt;
&lt;th&gt;.NET 5+&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Years&lt;/td&gt;
&lt;td&gt;2002–2019 (4.8.1 in 2022)&lt;/td&gt;
&lt;td&gt;2016–2019&lt;/td&gt;
&lt;td&gt;2020 →&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;OS&lt;/td&gt;
&lt;td&gt;Windows only&lt;/td&gt;
&lt;td&gt;Windows, Linux, macOS&lt;/td&gt;
&lt;td&gt;Windows, Linux, macOS, mobile (MAUI), WebAssembly&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Source&lt;/td&gt;
&lt;td&gt;Closed (reference source available)&lt;/td&gt;
&lt;td&gt;Open source (MIT)&lt;/td&gt;
&lt;td&gt;Open source&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Deployment&lt;/td&gt;
&lt;td&gt;Machine-wide install, part of Windows&lt;/td&gt;
&lt;td&gt;Side-by-side, self-contained possible&lt;/td&gt;
&lt;td&gt;Same + single-file, Native AOT&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Web&lt;/td&gt;
&lt;td&gt;ASP.NET Web Forms, MVC 5, Web API 2&lt;/td&gt;
&lt;td&gt;ASP.NET Core&lt;/td&gt;
&lt;td&gt;ASP.NET Core&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Performance&lt;/td&gt;
&lt;td&gt;Good&lt;/td&gt;
&lt;td&gt;Much faster&lt;/td&gt;
&lt;td&gt;Fastest; improves every release&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Status&lt;/td&gt;
&lt;td&gt;Maintenance only&lt;/td&gt;
&lt;td&gt;Out of support&lt;/td&gt;
&lt;td&gt;Active&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Mono&lt;/strong&gt; (2004, open source, by Ximian → Xamarin → Microsoft) ran .NET on Linux/macOS/mobile and powers Unity and Xamarin; today its runtime is used inside .NET for mobile and WebAssembly.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Interview tip:&lt;/strong&gt; "Why did they skip .NET 4?" — to avoid confusion with .NET Framework 4.x; .NET 5 dropped "Core" from the name because it became &lt;em&gt;the&lt;/em&gt; .NET going forward.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Interview questions on .NET Internals
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What is the CLR and what does it do?
&lt;/h3&gt;

&lt;p&gt;The Common Language Runtime is .NET's execution engine. It loads assemblies, verifies type safety, JIT-compiles IL to native code, manages memory with the garbage collector, handles exceptions, threads and synchronisation, provides interop with native code and exposes debugging/profiling services. Code running under it is "managed code".&lt;/p&gt;

&lt;h3&gt;
  
  
  What are CTS and CLS?
&lt;/h3&gt;

&lt;p&gt;CTS (Common Type System) defines how types are declared and used in .NET — value vs reference types, inheritance, members, visibility — so all languages share one type system (C# &lt;code&gt;int&lt;/code&gt; = VB.NET &lt;code&gt;Integer&lt;/code&gt; = &lt;code&gt;System.Int32&lt;/code&gt;). CLS (Common Language Specification) is a subset of CTS rules that every .NET language supports, so a CLS-compliant library can be used from any language (e.g. avoid public unsigned types or names differing only in case).&lt;/p&gt;

&lt;h3&gt;
  
  
  What is IL (MSIL/CIL) and what does the JIT do?
&lt;/h3&gt;

&lt;p&gt;IL is the CPU-independent, stack-based intermediate code the C#/VB.NET compilers produce, stored with metadata in assemblies. At runtime the JIT compiles each method's IL to native machine code on its first call, optimised for the actual CPU; tiered compilation starts with quick code and re-compiles hot methods with full optimisation. ReadyToRun and Native AOT precompile to reduce startup time.&lt;/p&gt;




&lt;p&gt;Read the &lt;a href="https://devladder.pages.dev/courses/dotnet-internals/lessons/dotnet-framework-vs-dotnet-core-vs-dotnet-5-the-history-explained" rel="noopener noreferrer"&gt;full lesson with progress tracking&lt;/a&gt; and the rest of the course on &lt;strong&gt;DevLadder&lt;/strong&gt; — free step-by-step tutorials and interview questions for developers.&lt;/p&gt;

&lt;p&gt;Next in the course: &lt;a href="https://devladder.pages.dev/courses/dotnet-internals/lessons/clr-cts-cls-what-each-one-does" rel="noopener noreferrer"&gt;CLR, CTS, CLS — what each one does&lt;/a&gt; →&lt;/p&gt;

</description>
      <category>dotnet</category>
      <category>csharp</category>
      <category>beginners</category>
      <category>interview</category>
    </item>
    <item>
      <title>Program structure, modules and the Main method — VB.NET</title>
      <dc:creator>DIVAKAR UPADHYAY</dc:creator>
      <pubDate>Sun, 08 Nov 2026 06:05:54 +0000</pubDate>
      <link>https://dev.to/divakarupadhyay/program-structure-modules-and-the-main-method-vbnet-49d5</link>
      <guid>https://dev.to/divakarupadhyay/program-structure-modules-and-the-main-method-vbnet-49d5</guid>
      <description>&lt;p&gt;&lt;em&gt;Lesson 1 of 12 in the free &lt;a href="https://devladder.pages.dev/courses/vbnet" rel="noopener noreferrer"&gt;VB.NET — Visual Basic .NET from Basics to Advanced (with C# Comparison)&lt;/a&gt; course on DevLadder.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vb"&gt;&lt;code&gt;&lt;span class="kd"&gt;Option Strict On&lt;/span&gt;          &lt;span class="c1"&gt;' no implicit narrowing conversions or late binding — always turn on&lt;/span&gt;
&lt;span class="kd"&gt;Option Explicit On&lt;/span&gt;        &lt;span class="c1"&gt;' every variable must be declared&lt;/span&gt;
&lt;span class="k"&gt;Option&lt;/span&gt; &lt;span class="n"&gt;Infer&lt;/span&gt; &lt;span class="k"&gt;On&lt;/span&gt;           &lt;span class="c1"&gt;' allow Dim x = 5 (type inferred)&lt;/span&gt;

&lt;span class="k"&gt;Imports&lt;/span&gt; &lt;span class="nn"&gt;System.Text&lt;/span&gt;       &lt;span class="c1"&gt;' = C# using&lt;/span&gt;

&lt;span class="k"&gt;Namespace&lt;/span&gt; &lt;span class="nn"&gt;Divakar.Shop&lt;/span&gt;
    &lt;span class="k"&gt;Module&lt;/span&gt; &lt;span class="nn"&gt;Program&lt;/span&gt;                       &lt;span class="c1"&gt;' a Module = C# static class; members are Shared automatically&lt;/span&gt;
        &lt;span class="k"&gt;Sub&lt;/span&gt; &lt;span class="nf"&gt;Main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt; &lt;span class="ow"&gt;As&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
            &lt;span class="nb"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hello, Divakar!"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;Dim&lt;/span&gt; &lt;span class="nv"&gt;name&lt;/span&gt; &lt;span class="ow"&gt;As&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;If&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Length&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="s"&gt;"world"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="nb"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="s"&gt;"Welcome {name}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;       &lt;span class="c1"&gt;' string interpolation (VB 14)&lt;/span&gt;
        &lt;span class="k"&gt;End&lt;/span&gt; &lt;span class="k"&gt;Sub&lt;/span&gt;
    &lt;span class="k"&gt;End&lt;/span&gt; &lt;span class="k"&gt;Module&lt;/span&gt;
&lt;span class="k"&gt;End&lt;/span&gt; &lt;span class="k"&gt;Namespace&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Statements end at the &lt;strong&gt;line break&lt;/strong&gt; (no semicolons); use &lt;code&gt;_&lt;/code&gt; for explicit line continuation, though VB 10+ allows implicit continuation after operators, commas and opening brackets.&lt;/li&gt;
&lt;li&gt;Comments start with &lt;code&gt;'&lt;/code&gt; (or &lt;code&gt;REM&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;Blocks end with &lt;code&gt;End X&lt;/code&gt; (&lt;code&gt;End If&lt;/code&gt;, &lt;code&gt;End Sub&lt;/code&gt;, &lt;code&gt;End Class&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;Keywords and identifiers are &lt;strong&gt;case-insensitive&lt;/strong&gt; (&lt;code&gt;dim&lt;/code&gt; = &lt;code&gt;Dim&lt;/code&gt;; the IDE fixes casing).&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;C#&lt;/th&gt;
&lt;th&gt;VB.NET&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;using System;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;Imports System&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;static class Helpers&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;Module Helpers&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;static void Main(string[] args)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;Sub Main(args As String())&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;// comment&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;' comment&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;Console.WriteLine("x");&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;Console.WriteLine("x")&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Interview questions on VB.NET
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What is the difference between VB.NET and C#?
&lt;/h3&gt;

&lt;p&gt;Both compile to the same IL and run on the same CLR with the same libraries, so performance is the same. Differences are syntax and features: VB.NET uses English-like keywords, is case-insensitive, line-based with &lt;code&gt;End&lt;/code&gt; blocks, has XML literals, &lt;code&gt;My&lt;/code&gt; namespace, &lt;code&gt;WithEvents/Handles&lt;/code&gt; and optional late binding; C# uses C-style syntax, is case-sensitive and gets new language features every year while VB.NET has been feature-stable since 2020. Most new projects use C#; VB.NET is mainly maintained in legacy systems.&lt;/p&gt;

&lt;h3&gt;
  
  
  What do Option Strict, Option Explicit and Option Infer do?
&lt;/h3&gt;

&lt;p&gt;Option Explicit On requires variables to be declared. Option Strict On disallows implicit narrowing conversions and late binding — catching type errors at compile time (strongly recommended). Option Infer On lets &lt;code&gt;Dim x = 5&lt;/code&gt; infer the type from the initializer. Set them per project (Compile settings) or per file at the top.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is the difference between Sub and Function?
&lt;/h3&gt;

&lt;p&gt;A &lt;code&gt;Sub&lt;/code&gt; performs an action and returns no value (C# &lt;code&gt;void&lt;/code&gt; method). A &lt;code&gt;Function&lt;/code&gt; returns a value with &lt;code&gt;Return&lt;/code&gt; (or by assigning to the function name in old code). Both can take ByVal/ByRef, Optional and ParamArray parameters.&lt;/p&gt;




&lt;p&gt;Read the &lt;a href="https://devladder.pages.dev/courses/vbnet/lessons/program-structure-modules-and-the-main-method" rel="noopener noreferrer"&gt;full lesson with progress tracking&lt;/a&gt; and the rest of the course on &lt;strong&gt;DevLadder&lt;/strong&gt; — free step-by-step tutorials and interview questions for developers.&lt;/p&gt;

&lt;p&gt;Next in the course: &lt;a href="https://devladder.pages.dev/courses/vbnet/lessons/data-types-variables-constants-and-conversions" rel="noopener noreferrer"&gt;Data types, variables, constants and conversions&lt;/a&gt; →&lt;/p&gt;

</description>
      <category>dotnet</category>
      <category>vbnet</category>
      <category>beginners</category>
      <category>interview</category>
    </item>
    <item>
      <title>What C# and .NET are — C# Language</title>
      <dc:creator>DIVAKAR UPADHYAY</dc:creator>
      <pubDate>Sun, 08 Nov 2026 06:04:34 +0000</pubDate>
      <link>https://dev.to/divakarupadhyay/what-c-and-net-are-c-language-2ghm</link>
      <guid>https://dev.to/divakarupadhyay/what-c-and-net-are-c-language-2ghm</guid>
      <description>&lt;p&gt;&lt;em&gt;Lesson 1 of 38 in the free &lt;a href="https://devladder.pages.dev/courses/csharp" rel="noopener noreferrer"&gt;C# Language — Basics to Advanced&lt;/a&gt; course on DevLadder.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;C# is the &lt;strong&gt;language&lt;/strong&gt;; .NET is the &lt;strong&gt;platform&lt;/strong&gt; (runtime + base class library + SDK). You write C#, the compiler produces IL, and the .NET runtime executes it.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;CLR&lt;/strong&gt; (Common Language Runtime): JIT, GC, type safety, exception handling, threading.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;BCL&lt;/strong&gt; (Base Class Library): &lt;code&gt;System&lt;/code&gt;, &lt;code&gt;System.Collections.Generic&lt;/code&gt;, &lt;code&gt;System.IO&lt;/code&gt;, &lt;code&gt;System.Net.Http&lt;/code&gt;, ...&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;CTS / CLS&lt;/strong&gt;: the common type system that lets C#, F# and VB.NET interoperate.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Program.cs — a complete program using top-level statements (C# 9+)&lt;/span&gt;
&lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hello, Divakar!"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Length&lt;/span&gt; &lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"world"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;$"Hello, &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;dotnet new console &lt;span class="nt"&gt;-n&lt;/span&gt; HelloApp
&lt;span class="nb"&gt;cd &lt;/span&gt;HelloApp
dotnet run &lt;span class="nt"&gt;--&lt;/span&gt; Divakar
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Interview tip:&lt;/strong&gt; "Managed code" = code whose execution is managed by the CLR (memory, security, exceptions). "Unmanaged code" = native code outside the CLR, e.g. Win32 DLLs called via P/Invoke.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Interview questions on C# Language
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What is the difference between a value type and a reference type?
&lt;/h3&gt;

&lt;p&gt;A &lt;strong&gt;value type&lt;/strong&gt; variable holds the data itself (&lt;code&gt;int&lt;/code&gt;, &lt;code&gt;bool&lt;/code&gt;, &lt;code&gt;decimal&lt;/code&gt;, &lt;code&gt;DateTime&lt;/code&gt;, any &lt;code&gt;struct&lt;/code&gt;/&lt;code&gt;enum&lt;/code&gt;). Assigning it copies the value. A &lt;strong&gt;reference type&lt;/strong&gt; variable holds a reference to an object on the managed heap (&lt;code&gt;class&lt;/code&gt;, &lt;code&gt;string&lt;/code&gt;, arrays, delegates, &lt;code&gt;record&lt;/code&gt;). Assigning it copies the reference, so two variables can point to the same object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;List&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;();&lt;/span&gt; &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;   &lt;span class="c1"&gt;// a.Count == 1 — same object&lt;/span&gt;
&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;++;&lt;/span&gt;                       &lt;span class="c1"&gt;// x is still 1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Value types are stored inline (stack for locals, inside the parent object for fields); reference-type objects always live on the heap and are cleaned up by the GC.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is the difference between &lt;code&gt;string&lt;/code&gt; and &lt;code&gt;StringBuilder&lt;/code&gt;?
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;string&lt;/code&gt; is &lt;strong&gt;immutable&lt;/strong&gt;: every concatenation creates a new string object, so building a string in a loop causes many allocations (O(n²) copying). &lt;code&gt;StringBuilder&lt;/code&gt; keeps a &lt;strong&gt;mutable buffer&lt;/strong&gt; and appends in place; call &lt;code&gt;ToString()&lt;/code&gt; once at the end. Use &lt;code&gt;StringBuilder&lt;/code&gt; for loops or many appends, plain strings/interpolation for a handful of pieces.&lt;/p&gt;

&lt;h3&gt;
  
  
  Explain &lt;code&gt;const&lt;/code&gt; vs &lt;code&gt;readonly&lt;/code&gt; vs &lt;code&gt;static readonly&lt;/code&gt;.
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;const&lt;/code&gt;: compile-time constant, implicitly static, only primitives/strings; the value is &lt;strong&gt;baked into callers&lt;/strong&gt; at compile time.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;readonly&lt;/code&gt;: instance field assigned at declaration or in a constructor; can differ per object.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;static readonly&lt;/code&gt;: one value per type, computed at runtime (e.g. &lt;code&gt;static readonly HttpClient Client = new()&lt;/code&gt;).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Gotcha: if library A has &lt;code&gt;public const int Max = 10&lt;/code&gt; and app B uses it, changing it to 20 in A does nothing in B until B is recompiled. Use &lt;code&gt;static readonly&lt;/code&gt; for values that may change.&lt;/p&gt;




&lt;p&gt;Read the &lt;a href="https://devladder.pages.dev/courses/csharp/lessons/what-csharp-and-dotnet-are" rel="noopener noreferrer"&gt;full lesson with progress tracking&lt;/a&gt; and the rest of the course on &lt;strong&gt;DevLadder&lt;/strong&gt; — free step-by-step tutorials and interview questions for developers.&lt;/p&gt;

&lt;p&gt;Next in the course: &lt;a href="https://devladder.pages.dev/courses/csharp/lessons/first-program-namespaces-and-keywords" rel="noopener noreferrer"&gt;First program, namespaces and keywords&lt;/a&gt; →&lt;/p&gt;

</description>
      <category>dotnet</category>
      <category>csharp</category>
      <category>beginners</category>
      <category>interview</category>
    </item>
  </channel>
</rss>
