<!DOCTYPE html><html lang="en"> <head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>C# (C-sharp) explained: the language, .NET &amp; key features | KB Cafe</title><meta name="description" content="A clear reference on C#: what the language is, its relationship to .NET, the type system, the signature features (LINQ, async/await, generics, records), C# vs Java and C++, with code, and FAQs."><link rel="canonical" href="https://kbcafe.com/csharp"><script type="application/ld+json">{"@context":"https://schema.org","@type":"Organization","name":"KB Cafe","url":"https://kbcafe.com/","logo":"https://kbcafe.com/logo.png"}</script><script type="application/ld+json">{"@context":"https://schema.org","@type":"WebSite","name":"KB Cafe","url":"https://kbcafe.com/","potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://kbcafe.com/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}</script><script type="application/ld+json">{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"KB Cafe","item":"https://kbcafe.com/"},{"@type":"ListItem","position":2,"name":"Knowledge Base","item":"https://kbcafe.com/reference"},{"@type":"ListItem","position":3,"name":"C# (C-sharp)","item":"https://kbcafe.com/csharp"}]}</script><link rel="alternate" type="application/rss+xml" title="KB Cafe" href="/feed.xml"><!-- favicon = the KB cup mark (generated from logo.png via scripts/gen-favicon.cjs) --><link rel="icon" href="/favicon.ico" sizes="any"><link rel="icon" type="image/png" sizes="32x32" href="/favicon-32.png"><link rel="icon" type="image/png" sizes="16x16" href="/favicon-16.png"><link rel="apple-touch-icon" href="/apple-touch-icon.png"><meta property="og:title" content="C# (C-sharp) explained: the language, .NET &amp; key features | KB Cafe"><meta property="og:description" content="A clear reference on C#: what the language is, its relationship to .NET, the type system, the signature features (LINQ, async/await, generics, records), C# vs Java and C++, with code, and FAQs."><meta property="og:type" content="website"><meta property="og:url" content="https://kbcafe.com/csharp"><meta property="og:site_name" content="KB Cafe"><meta property="og:image" content="https://kbcafe.com/og.png"><meta property="og:image:width" content="1200"><meta property="og:image:height" content="630"><meta property="og:image:alt" content="C# (C-sharp) explained: the language, .NET &amp; key features | KB Cafe"><meta name="twitter:card" content="summary_large_image"><meta name="twitter:image" content="https://kbcafe.com/og.png"><link rel="preconnect" href="https://fonts.googleapis.com"><link rel="preconnect" href="https://fonts.gstatic.com" crossorigin><link href="https://fonts.googleapis.com/css2?family=Sora:wght@600;700;800&family=Hanken+Grotesk:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;700&display=swap" rel="stylesheet"><!-- progress tracking: 100% local (localStorage), no accounts, no tracking, never leaves the device --><script>
  window.kbProgress = {
    k: 'kbcafe-progress',
    all() { try { return new Set(JSON.parse(localStorage.getItem(this.k) || '[]')); } catch { return new Set(); } },
    has(h) { return this.all().has(h); },
    save(s) { try { localStorage.setItem(this.k, JSON.stringify([...s])); } catch {} },
    toggle(h) { const s = this.all(); s.has(h) ? s.delete(h) : s.add(h); this.save(s); return s.has(h); },
    set(h, on) { const s = this.all(); on ? s.add(h) : s.delete(h); this.save(s); },
    count() { return this.all().size },
  };
  // Shared "learn by doing" reward: bumps XP and a per-day streak (local only), fires an event the
  // header badge listens to. Called by Practice exercises, Capstones, and path-step check-offs.
  window.kbAward = function (n) {
    try {
      var xp = (JSON.parse(localStorage.getItem('kb-xp') || '0') || 0) + (n || 0);
      localStorage.setItem('kb-xp', JSON.stringify(xp));
      var st = JSON.parse(localStorage.getItem('kb-streak') || '{"d":"","n":0}');
      var t = new Date().toISOString().slice(0, 10);
      if (st.d !== t) { var y = new Date(Date.now() - 864e5).toISOString().slice(0, 10); st.n = (st.d === y) ? (st.n || 0) + 1 : 1; st.d = t; localStorage.setItem('kb-streak', JSON.stringify(st)); }
      window.dispatchEvent(new CustomEvent('kb-xp-change'));
      return st.n || 1;
    } catch (e) { return 0; }
  };
  // Award XP once per unique key (for path steps / capstones that can be re-toggled).
  window.kbAwardOnce = function (key, n) {
    try { var a = JSON.parse(localStorage.getItem('kb-xp-awarded') || '{}'); if (a[key]) return 0; a[key] = 1; localStorage.setItem('kb-xp-awarded', JSON.stringify(a)); return window.kbAward(n); } catch (e) { return 0; }
  };
  // Header streak/XP badge: appears once any XP is earned, refreshes on every change.
  (function () {
    function render() {
      var xp = 0, st = 0;
      try { xp = JSON.parse(localStorage.getItem('kb-xp') || '0') || 0; var s = JSON.parse(localStorage.getItem('kb-streak') || '{}'); st = (s && s.n) || 0; } catch (e) {}
      ['nav-xp', 'sb-xp'].forEach(function (id) {
        var el = document.getElementById(id); if (!el) return;
        if (xp > 0) { el.hidden = false; var a = el.querySelector('[data-st]'), b = el.querySelector('[data-xp]'); if (a) a.textContent = st; if (b) b.textContent = xp; }
        else el.hidden = true;
      });
    }
    window.addEventListener('kb-xp-change', render);
    if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', render); else render();
  })();
</script><!-- Privacy-friendly analytics by Plausible (cookieless, no personal data, aggregate only) --><script async src="https://plausible.io/js/pa-jVkxTQgljXyiSvPl7VnJU.js"></script><script>
  window.plausible = window.plausible || function () { (plausible.q = plausible.q || []).push(arguments) };
  plausible.init = plausible.init || function (i) { plausible.o = i || {} };
  plausible.init();
  // safe wrapper for our 3 aggregate events (Path Start / Path Complete / Tool Used)
  window.kbTrack = function (name, props) { try { window.plausible(name, props ? { props: props } : undefined); } catch (e) {} };
</script><style>.share[data-astro-cid-ung7bpju]{--x:#0b0b0b;--reddit:#FF4500;--linkedin:#0A66C2;--facebook:#1877F2;display:flex;align-items:center;gap:14px;flex-wrap:wrap}.share[data-astro-cid-ung7bpju].prominent{justify-content:space-between;border:1.5px solid var(--line);border-radius:16px;background:var(--cream);padding:16px 20px;margin:28px 0 4px}.share[data-astro-cid-ung7bpju].subtle{margin:30px 0 0}.share[data-astro-cid-ung7bpju].t-caption{flex-direction:column;align-items:flex-start;gap:9px}.share-copy[data-astro-cid-ung7bpju]{display:flex;flex-direction:column;gap:2px}.share-copy[data-astro-cid-ung7bpju] strong[data-astro-cid-ung7bpju]{font-family:var(--font-display);font-weight:800;font-size:16px;color:var(--ink)}.share-copy[data-astro-cid-ung7bpju] span[data-astro-cid-ung7bpju]{font-size:13px;color:var(--ink-soft)}.share-copy[data-astro-cid-ung7bpju] span[data-astro-cid-ung7bpju] b[data-astro-cid-ung7bpju]{font-weight:800;color:var(--ink)}.share-cap[data-astro-cid-ung7bpju]{font-family:var(--font-mono);font-size:10.5px;font-weight:700;letter-spacing:.14em;text-transform:uppercase;color:var(--ink-soft)}.share-btns[data-astro-cid-ung7bpju]{display:flex;align-items:center;gap:8px;flex-wrap:wrap}.tone-x[data-astro-cid-ung7bpju]{--tone:var(--x)}.tone-reddit[data-astro-cid-ung7bpju]{--tone:var(--reddit)}.tone-linkedin[data-astro-cid-ung7bpju]{--tone:var(--linkedin)}.tone-facebook[data-astro-cid-ung7bpju]{--tone:var(--facebook)}.tone-mail[data-astro-cid-ung7bpju],.tone-link[data-astro-cid-ung7bpju]{--tone:var(--coral)}.sh[data-astro-cid-ung7bpju]{display:grid;place-items:center;border:1.5px solid var(--line);background:var(--cream);color:var(--ink-soft);cursor:pointer;text-decoration:none;transition:transform .12s,border-color .12s,color .12s,background .12s}.sh[data-astro-cid-ung7bpju] svg[data-astro-cid-ung7bpju]{width:18px;height:18px}.t-chip[data-astro-cid-ung7bpju] .sh[data-astro-cid-ung7bpju],.t-caption[data-astro-cid-ung7bpju] .sh[data-astro-cid-ung7bpju]{width:40px;height:40px;border-radius:11px}.t-chip[data-astro-cid-ung7bpju] .sh[data-astro-cid-ung7bpju]{color:var(--tone,var(--ink-soft))}.t-chip[data-astro-cid-ung7bpju] .sh[data-astro-cid-ung7bpju]:hover{transform:translateY(-2px);border-color:currentColor}.t-chip[data-astro-cid-ung7bpju] .sh-launch[data-astro-cid-ung7bpju]{color:var(--ink);background:var(--paper-2);border-color:transparent}.t-chip[data-astro-cid-ung7bpju] .sh-launch[data-astro-cid-ung7bpju]:hover{color:#fff;background:var(--coral)}.t-chip[data-astro-cid-ung7bpju] .sh-div[data-astro-cid-ung7bpju]{width:1px;height:24px;background:var(--line);margin:0 3px}.t-caption[data-astro-cid-ung7bpju] .sh-launch[data-astro-cid-ung7bpju]{color:var(--ink)}.t-caption[data-astro-cid-ung7bpju] .sh[data-astro-cid-ung7bpju]:hover{transform:translateY(-2px);color:var(--tone,var(--coral));border-color:currentColor}.t-caption[data-astro-cid-ung7bpju] .sh-launch[data-astro-cid-ung7bpju]:hover{color:#fff;background:var(--coral);border-color:var(--coral)}.share-bar[data-astro-cid-ung7bpju]{display:inline-flex;align-items:center;background:var(--paper);border-radius:12px;padding:4px;gap:2px;flex-wrap:wrap}.t-bar[data-astro-cid-ung7bpju] .sh[data-astro-cid-ung7bpju]{width:38px;height:38px;border-radius:9px;border:0;background:transparent;color:var(--tone,var(--ink-soft))}.t-bar[data-astro-cid-ung7bpju] .sh[data-astro-cid-ung7bpju]:hover{background:var(--cream);transform:translateY(-1px)}.t-bar[data-astro-cid-ung7bpju] .sh-launch[data-astro-cid-ung7bpju]{color:var(--ink)}.t-bar[data-astro-cid-ung7bpju] .seg-div[data-astro-cid-ung7bpju]{width:1px;height:22px;background:var(--line);margin:0 5px}.share-done[data-astro-cid-ung7bpju]{font-family:var(--font-mono);font-size:12px;font-weight:700;color:#2f7d32;margin-left:4px}@media(max-width:560px){.share[data-astro-cid-ung7bpju].prominent{flex-direction:column;align-items:flex-start}}
.read-progress{position:fixed;top:0;left:0;right:0;height:3px;background:transparent;z-index:60;pointer-events:none}.read-progress i{display:block;height:100%;width:0;background:var(--coral)}.read-meta{display:inline-flex;align-items:center;gap:7px;font-family:var(--font-mono);font-size:11.5px;font-weight:700;letter-spacing:.05em;text-transform:uppercase;color:var(--ink-soft);margin:0 0 4px}.read-meta .rm-dot{width:6px;height:6px;border-radius:50%;background:var(--gold)}.toc a.is-active{color:var(--ink);text-decoration:underline;text-decoration-color:var(--coral);text-decoration-thickness:2px;text-underline-offset:3px}@media(min-width:920px){.toc{position:sticky;top:10px;z-index:5;max-height:42vh;overflow:auto;box-shadow:0 6px 18px #1e18130d}}.prose .code{position:relative}.code-copy{position:absolute;top:8px;right:8px;font-family:var(--font-mono);font-size:10.5px;font-weight:700;letter-spacing:.06em;text-transform:uppercase;color:#f4e9d6;background:#ffffff1a;border:1px solid rgba(255,255,255,.18);border-radius:7px;padding:5px 9px;cursor:pointer;opacity:.5;transition:opacity .14s,background .14s}.prose .code:hover .code-copy{opacity:1}.code-copy:hover{background:#ffffff38}.code-copy.ok{color:#9ff0c0;border-color:#9ff0c073}@media(prefers-reduced-motion:no-preference){.read-progress i{transition:width .1s linear}}
</style><link rel="stylesheet" href="/_astro/Layout.fq0CbVn6.css"><link rel="stylesheet" href="/_astro/QuizShare.DBNmFO-V.css"><link rel="stylesheet" href="/_astro/ReferencePage.CLNhAHSu.css"></head> <body class> <!-- reusable marks --> <svg width="0" height="0" style="position:absolute" aria-hidden="true"><defs> <symbol id="kb-mark" viewBox="0 0 64 64"> <path d="M19 6 H45 A4 4 0 0 1 49 10 V58 L32 47 L15 58 V10 A4 4 0 0 1 19 6 Z" fill="#EE4B2B"></path> <text x="32" y="31" text-anchor="middle" font-family="Bricolage Grotesque,sans-serif" font-weight="800" font-size="20" fill="#FFFCF5" letter-spacing="-1">KB</text> </symbol> <symbol id="kb-mark-mini" viewBox="0 0 64 64"> <path d="M19 6 H45 A4 4 0 0 1 49 10 V58 L32 47 L15 58 V10 A4 4 0 0 1 19 6 Z" fill="#F4B423"></path> <text x="32" y="31" text-anchor="middle" font-family="Bricolage Grotesque,sans-serif" font-weight="800" font-size="20" fill="#1E1813" letter-spacing="-1">KB</text> </symbol> <symbol id="cup" viewBox="0 0 48 48"> <path d="M10 19h21v9a7 7 0 0 1-7 7h-7a7 7 0 0 1-7-7v-9Z" fill="none" stroke="#F4B423" stroke-width="2.6"></path> <path d="M31 21h3.5a4 4 0 0 1 0 8H31" fill="none" stroke="#F4B423" stroke-width="2.6"></path> <path d="M16 14q-2-2.4 0-4.8q2-2.4 0-4.8" fill="none" stroke="#FFFCF5" stroke-width="2.2" stroke-linecap="round" opacity=".85"></path> <path d="M22 14q2-2.4 0-4.8q-2-2.4 0-4.8" fill="none" stroke="#FFFCF5" stroke-width="2.2" stroke-linecap="round" opacity=".85"></path> </symbol> </defs></svg> <nav class="site-nav"> <button class="sb-burger" id="sb-burger" type="button" aria-label="Open menu" aria-expanded="false"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path class="sbb-bars" d="M4 7h16M4 12h16M4 17h16"></path><path class="sbb-x" d="M6 6l12 12M18 6 6 18"></path></svg></button> <a class="brand" href="/" aria-label="KB Cafe, home"> <img class="mark" src="/logo.png" width="50" height="50" alt="KB Cafe, a coffee cup with an open book inside"> <span class="cf">Cafe</span> <span class="brand-hint" aria-hidden="true">Knowledge Base</span> </a> <div class="nav-center" id="nav-center"></div> <div class="nav-links"> <a href="/" class>Home</a> <a href="/reference" class="on">Knowledge Base</a> <a href="/tools" class>Tools</a> <a href="/learn" class>Learn</a> <a class="nav-xp" id="nav-xp" href="/learn" hidden title="Your practice streak and XP, saved on this device"><span class="nx-ic nx-flame"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M8.5 14.5A2.5 2.5 0 0 0 11 12c0-1.38-.5-2-1-3-1.07-2.14-.22-4.05 2-6 .5 2.5 2 4.9 4 6.5 2 1.6 3 3.5 3 5.5a7 7 0 1 1-14 0c0-1.15.43-2.29 1-3a2.5 2.5 0 0 0 2.5 2.5Z"></path></svg></span><b data-st>0</b><span class="nx-x"><span class="nx-ic nx-star"><svg viewBox="0 0 24 24" fill="currentColor"><path d="M11.5 2.3a.53.53 0 0 1 .95 0l2.31 4.68a2.1 2.1 0 0 0 1.6 1.16l5.16.76a.53.53 0 0 1 .3.9l-3.74 3.64a2.1 2.1 0 0 0-.61 1.88l.88 5.14a.53.53 0 0 1-.77.56l-4.62-2.43a2.1 2.1 0 0 0-1.97 0L6.4 21.94a.53.53 0 0 1-.77-.56l.88-5.14a2.1 2.1 0 0 0-.61-1.88L2.16 10.72a.53.53 0 0 1 .29-.9l5.17-.76a2.1 2.1 0 0 0 1.6-1.16z"></path></svg></span><b data-xp>0</b></span></a> <button class="nav-study" id="nav-study" type="button" aria-pressed="false" aria-label="Open a study window: read two pages side by side" title="Study window: open a second page beside this one"> <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect width="18" height="18" x="3" y="3" rx="2"></rect><path d="M15 3v18"></path><path d="m10 15-3-3 3-3"></path></svg> <span>Study</span> </button> <div class="nav-search" id="navsearch"> <button class="ns-toggle" id="ns-toggle" type="button" aria-label="Search"> <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round"><circle cx="11" cy="11" r="7"></circle><path d="m21 21-4.3-4.3"></path></svg> <span class="ns-text">Search</span><kbd class="ns-key">⌘K</kbd> </button> <form class="ns-form" id="ns-form" action="/search" method="get" role="search"> <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round"><circle cx="11" cy="11" r="7"></circle><path d="m21 21-4.3-4.3"></path></svg> <input id="ns-input" name="q" type="text" placeholder="Search tools, references & AI…" autocomplete="off"> <button class="ns-go" type="submit" style="background:var(--coral)">Go</button> </form> </div> </div> </nav> <div class="wrap wrap-sb"> <div class="layout-sb"> <aside class="kb-sb" id="kb-sb" aria-label="Site navigation" data-astro-cid-ssfzsv2f> <div class="sb-bar" data-astro-cid-ssfzsv2f> <a class="sb-search" href="/search" data-astro-cid-ssfzsv2f><span class="sb-ic" data-astro-cid-ssfzsv2f><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round"><circle cx="11" cy="11" r="7"/><path d="m21 21-4.3-4.3"/></svg></span><span class="sb-lbl" data-astro-cid-ssfzsv2f>Search</span></a> <button class="sb-collapse" id="sb-collapse" type="button" aria-label="Collapse sidebar" title="Collapse" data-astro-cid-ssfzsv2f><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" data-astro-cid-ssfzsv2f><path d="m13 6-6 6 6 6M18 6l-6 6 6 6" data-astro-cid-ssfzsv2f></path></svg></button> <button class="sb-close" id="sb-close" type="button" aria-label="Close menu" title="Close" data-astro-cid-ssfzsv2f><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.3" stroke-linecap="round" data-astro-cid-ssfzsv2f><path d="M6 6l12 12M18 6 6 18" data-astro-cid-ssfzsv2f></path></svg></button> </div> <nav class="sb-primary" aria-label="Main" data-astro-cid-ssfzsv2f> <a class href="/" data-astro-cid-ssfzsv2f>Home</a> <a class href="/reference" data-astro-cid-ssfzsv2f>Knowledge Base</a> <a class href="/tools" data-astro-cid-ssfzsv2f>Tools</a> <a class href="/learn" data-astro-cid-ssfzsv2f>Learn</a> </nav> <a class="sb-xp" id="sb-xp" href="/learn" hidden data-astro-cid-ssfzsv2f><span class="sx-ic sx-flame" data-astro-cid-ssfzsv2f><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" data-astro-cid-ssfzsv2f><path d="M8.5 14.5A2.5 2.5 0 0 0 11 12c0-1.38-.5-2-1-3-1.07-2.14-.22-4.05 2-6 .5 2.5 2 4.9 4 6.5 2 1.6 3 3.5 3 5.5a7 7 0 1 1-14 0c0-1.15.43-2.29 1-3a2.5 2.5 0 0 0 2.5 2.5Z" data-astro-cid-ssfzsv2f></path></svg></span><b data-st data-astro-cid-ssfzsv2f>0</b>&nbsp;day streak<span class="sx-sep" data-astro-cid-ssfzsv2f>&middot;</span><span class="sx-ic sx-star" data-astro-cid-ssfzsv2f><svg viewBox="0 0 24 24" fill="currentColor" data-astro-cid-ssfzsv2f><path d="M11.5 2.3a.53.53 0 0 1 .95 0l2.31 4.68a2.1 2.1 0 0 0 1.6 1.16l5.16.76a.53.53 0 0 1 .3.9l-3.74 3.64a2.1 2.1 0 0 0-.61 1.88l.88 5.14a.53.53 0 0 1-.77.56l-4.62-2.43a2.1 2.1 0 0 0-1.97 0L6.4 21.94a.53.53 0 0 1-.77-.56l.88-5.14a2.1 2.1 0 0 0-.61-1.88L2.16 10.72a.53.53 0 0 1 .29-.9l5.17-.76a2.1 2.1 0 0 0 1.6-1.16z" data-astro-cid-ssfzsv2f></path></svg></span><b data-xp data-astro-cid-ssfzsv2f>0</b>&nbsp;XP</a> <nav class="sb-triage" data-astro-cid-ssfzsv2f> <span class="sb-h" data-astro-cid-ssfzsv2f>What are you doing?</span> <a class="sb-item" href="/beginner-ai" title="New to AI?, start from zero" data-astro-cid-ssfzsv2f> <span class="sb-ic" style="color:#3478f6" data-astro-cid-ssfzsv2f><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M11.017 2.814a1 1 0 0 1 1.966 0l1.051 5.558a2 2 0 0 0 1.594 1.594l5.558 1.051a1 1 0 0 1 0 1.966l-5.558 1.051a2 2 0 0 0-1.594 1.594l-1.051 5.558a1 1 0 0 1-1.966 0l-1.051-5.558a2 2 0 0 0-1.594-1.594l-5.558-1.051a1 1 0 0 1 0-1.966l5.558-1.051a2 2 0 0 0 1.594-1.594z"/><path d="M20 2v4"/><path d="M22 4h-4"/><circle cx="4" cy="20" r="2"/></svg></span> <span class="sb-lbl" data-astro-cid-ssfzsv2f><b data-astro-cid-ssfzsv2f>New to AI?</b><small data-astro-cid-ssfzsv2f>start from zero</small></span> </a><a class="sb-item" href="/learn-ai-infrastructure" title="Learn AI, the fundamentals" data-astro-cid-ssfzsv2f> <span class="sb-ic" style="color:var(--coral)" data-astro-cid-ssfzsv2f><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="round"><path d="M12 6S9 4 4 4v13c5 0 8 2 8 2s3-2 8-2V4c-5 0-8 2-8 2Z"/><path d="M12 6v15"/></svg></span> <span class="sb-lbl" data-astro-cid-ssfzsv2f><b data-astro-cid-ssfzsv2f>Learn AI</b><small data-astro-cid-ssfzsv2f>the fundamentals</small></span> </a><a class="sb-item" href="/learn-ai-agents" title="Build AI Agents, apps &amp; agents" data-astro-cid-ssfzsv2f> <span class="sb-ic" style="color:var(--coral)" data-astro-cid-ssfzsv2f><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="round"><path d="M12 3l8 4.5v9L12 21l-8-4.5v-9L12 3Z"/><path d="M12 12l8-4.5M12 12v9M12 12 4 7.5"/></svg></span> <span class="sb-lbl" data-astro-cid-ssfzsv2f><b data-astro-cid-ssfzsv2f>Build AI Agents</b><small data-astro-cid-ssfzsv2f>apps &amp; agents</small></span> </a><a class="sb-item" href="/learn-prompting" title="Get Better Answers, prompting" data-astro-cid-ssfzsv2f> <span class="sb-ic" style="color:var(--coral)" data-astro-cid-ssfzsv2f><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12a8 8 0 0 1-11.5 7.2L4 20l1-4.5A8 8 0 1 1 21 12Z"/><path d="M9 11h6M9 14h4"/></svg></span> <span class="sb-lbl" data-astro-cid-ssfzsv2f><b data-astro-cid-ssfzsv2f>Get Better Answers</b><small data-astro-cid-ssfzsv2f>prompting</small></span> </a><a class="sb-item" href="/learn-ai-coding" title="Code with AI, write real code" data-astro-cid-ssfzsv2f> <span class="sb-ic" style="color:var(--coral)" data-astro-cid-ssfzsv2f><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M14.7 6.3a4 4 0 0 0-5.2 5.2L3 18l3 3 6.5-6.5a4 4 0 0 0 5.2-5.2l-2.6 2.6-2.3-2.3 2.6-2.6Z"/></svg></span> <span class="sb-lbl" data-astro-cid-ssfzsv2f><b data-astro-cid-ssfzsv2f>Code with AI</b><small data-astro-cid-ssfzsv2f>write real code</small></span> </a><a class="sb-item" href="/learn-ai-automation" title="Automation, workflows &amp; agents" data-astro-cid-ssfzsv2f> <span class="sb-ic" style="color:var(--coral)" data-astro-cid-ssfzsv2f><svg viewBox="0 0 24 24" fill="currentColor"><path fill-rule="evenodd" d="M9.62 4.68 L10.37 1.73 L13.63 1.73 L14.38 4.68 L15.50 5.14 L18.11 3.59 L20.41 5.89 L18.86 8.50 L19.32 9.62 L22.27 10.37 L22.27 13.63 L19.32 14.38 L18.86 15.50 L20.41 18.11 L18.11 20.41 L15.50 18.86 L14.38 19.32 L13.63 22.27 L10.37 22.27 L9.62 19.32 L8.50 18.86 L5.89 20.41 L3.59 18.11 L5.14 15.50 L4.68 14.38 L1.73 13.63 L1.73 10.37 L4.68 9.62 L5.14 8.50 L3.59 5.89 L5.89 3.59 L8.50 5.14 Z M8.3 12 a3.7 3.7 0 1 0 7.4 0 a3.7 3.7 0 1 0 -7.4 0 Z"/></svg></span> <span class="sb-lbl" data-astro-cid-ssfzsv2f><b data-astro-cid-ssfzsv2f>Automation</b><small data-astro-cid-ssfzsv2f>workflows &amp; agents</small></span> </a><a class="sb-item" href="/ai-business" title="AI Business, grow &amp; monetize" data-astro-cid-ssfzsv2f> <span class="sb-ic" style="color:var(--coral)" data-astro-cid-ssfzsv2f><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="round"><rect x="3" y="7" width="18" height="13" rx="2"/><path d="M8 7V5a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2M3 13h18"/></svg></span> <span class="sb-lbl" data-astro-cid-ssfzsv2f><b data-astro-cid-ssfzsv2f>AI Business</b><small data-astro-cid-ssfzsv2f>grow &amp; monetize</small></span> </a> </nav> <div class="sb-sec" data-sec="explained" data-astro-cid-ssfzsv2f> <button class="sb-toggle" type="button" aria-expanded="false" data-astro-cid-ssfzsv2f><span class="sb-ic" data-astro-cid-ssfzsv2f><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="round"><path d="M12 6S9 4 4 4v13c5 0 8 2 8 2s3-2 8-2V4c-5 0-8 2-8 2Z"/><path d="M12 6v15"/></svg></span><span class="sb-lbl" data-astro-cid-ssfzsv2f>AI Explained</span><span class="sb-chev" data-astro-cid-ssfzsv2f><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><path d="m6 9 6 6 6-6"/></svg></span></button> <div class="sb-list" data-astro-cid-ssfzsv2f> <a class="sb-link" href="/what-is-a-context-window" data-astro-cid-ssfzsv2f>What is a context window?</a><a class="sb-link" href="/what-are-embeddings" data-astro-cid-ssfzsv2f>What are embeddings?</a><a class="sb-link" href="/what-is-a-vector-database" data-astro-cid-ssfzsv2f>What is a vector database?</a><a class="sb-link" href="/what-is-rag" data-astro-cid-ssfzsv2f>What is RAG (Retrieval-Augmented Generation)?</a><a class="sb-link" href="/what-is-agent-memory" data-astro-cid-ssfzsv2f>What is agent memory?</a><a class="sb-link" href="/what-is-mcp" data-astro-cid-ssfzsv2f>What is MCP (Model Context Protocol)?</a><a class="sb-link" href="/what-are-mcp-servers" data-astro-cid-ssfzsv2f>What are MCP servers?</a><a class="sb-link" href="/what-is-tool-calling" data-astro-cid-ssfzsv2f>What is tool calling (function calling)?</a><a class="sb-link" href="/how-to-build-an-ai-agent" data-astro-cid-ssfzsv2f>How to build an AI agent</a><a class="sb-link" href="/what-are-structured-outputs" data-astro-cid-ssfzsv2f>What are structured outputs?</a><a class="sb-link" href="/what-is-an-ai-hallucination" data-astro-cid-ssfzsv2f>What is an AI hallucination?</a><a class="sb-link" href="/what-are-reasoning-models" data-astro-cid-ssfzsv2f>What are reasoning models?</a><a class="sb-link" href="/what-are-ai-evals" data-astro-cid-ssfzsv2f>What are AI evals?</a><a class="sb-link" href="/prompt-injection" data-astro-cid-ssfzsv2f>Prompt injection and AI security</a><a class="sb-link" href="/how-to-prompt-claude-fable-5" data-astro-cid-ssfzsv2f>How to prompt Claude Fable 5</a><a class="sb-link" href="/how-to-write-code-with-ai" data-astro-cid-ssfzsv2f>How to write code with AI</a><a class="sb-link" href="/what-is-workflow-automation" data-astro-cid-ssfzsv2f>What is workflow automation?</a><a class="sb-link" href="/ai-agents-vs-workflows-vs-rpa" data-astro-cid-ssfzsv2f>AI agents vs workflows vs RPA</a><a class="sb-link" href="/webhooks-vs-polling" data-astro-cid-ssfzsv2f>Webhooks vs polling</a><a class="sb-link" href="/what-is-ai-orchestration" data-astro-cid-ssfzsv2f>What is AI orchestration?</a><a class="sb-link" href="/what-are-ai-loops" data-astro-cid-ssfzsv2f>What are AI loops?</a> <a class="sb-all" href="/ai" data-astro-cid-ssfzsv2f>All AI Explained →</a> </div> </div> <div class="sb-sec" data-sec="tools" data-astro-cid-ssfzsv2f> <button class="sb-toggle" type="button" aria-expanded="false" data-astro-cid-ssfzsv2f><span class="sb-ic" data-astro-cid-ssfzsv2f><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M14.7 6.3a4 4 0 0 0-5.2 5.2L3 18l3 3 6.5-6.5a4 4 0 0 0 5.2-5.2l-2.6 2.6-2.3-2.3 2.6-2.6Z"/></svg></span><span class="sb-lbl" data-astro-cid-ssfzsv2f>Use a tool</span><span class="sb-chev" data-astro-cid-ssfzsv2f><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><path d="m6 9 6 6 6-6"/></svg></span></button> <div class="sb-list" data-astro-cid-ssfzsv2f> <a class="sb-link" href="/token-counter" data-astro-cid-ssfzsv2f>token counter</a><a class="sb-link" href="/context-window-visualizer" data-astro-cid-ssfzsv2f>context window viz</a><a class="sb-link" href="/context-budget-analyzer" data-astro-cid-ssfzsv2f>context budget analyzer</a><a class="sb-link" href="/structured-output-builder" data-astro-cid-ssfzsv2f>structured output builder</a><a class="sb-link" href="/ai-pattern-explorer" data-astro-cid-ssfzsv2f>ai pattern explorer</a><a class="sb-link" href="/rag-chunking-visualizer" data-astro-cid-ssfzsv2f>rag chunking visualizer</a><a class="sb-link" href="/mcp-config-generator" data-astro-cid-ssfzsv2f>mcp config generator</a><a class="sb-link" href="/mcp-inspector" data-astro-cid-ssfzsv2f>mcp inspector</a><a class="sb-link" href="/prompt-linter" data-astro-cid-ssfzsv2f>prompt linter</a><a class="sb-link" href="/prompt-diff" data-astro-cid-ssfzsv2f>prompt diff</a><a class="sb-link" href="/prompt-simulator" data-astro-cid-ssfzsv2f>prompt simulator</a><a class="sb-link" href="/prompt-builder" data-astro-cid-ssfzsv2f>prompt builder</a><a class="sb-link" href="/prompt-optimizer" data-astro-cid-ssfzsv2f>prompt optimizer</a><a class="sb-link" href="/ai-coding-prompt-builder" data-astro-cid-ssfzsv2f>ai coding prompt builder</a><a class="sb-link" href="/good-vs-bad-prompts" data-astro-cid-ssfzsv2f>good vs bad prompts</a><a class="sb-link" href="/learning-path-builder" data-astro-cid-ssfzsv2f>learning path builder</a><a class="sb-link" href="/llm-vram-calculator" data-astro-cid-ssfzsv2f>llm vram calculator</a><a class="sb-link" href="/llm-cost-calculator" data-astro-cid-ssfzsv2f>llm cost calculator</a><a class="sb-link" href="/ai-profit-calculator" data-astro-cid-ssfzsv2f>ai profit calculator</a><a class="sb-link" href="/agent-memory-simulator" data-astro-cid-ssfzsv2f>agent memory simulator</a><a class="sb-link" href="/ai-pattern-builder" data-astro-cid-ssfzsv2f>ai pattern builder</a><a class="sb-link" href="/ai-stack-explainer" data-astro-cid-ssfzsv2f>ai stack explainer</a><a class="sb-link" href="/tool-call-visualizer" data-astro-cid-ssfzsv2f>tool call visualizer</a><a class="sb-link" href="/prompt-x-ray" data-astro-cid-ssfzsv2f>prompt x-ray</a><a class="sb-link" href="/embedding-explorer" data-astro-cid-ssfzsv2f>embedding explorer</a><a class="sb-link" href="/claim-checker" data-astro-cid-ssfzsv2f>claim &amp; citation checker</a><a class="sb-link" href="/scope-sorter" data-astro-cid-ssfzsv2f>scope sorter</a><a class="sb-link" href="/launch-rubric" data-astro-cid-ssfzsv2f>launch readiness rubric</a><a class="sb-link" href="/ai-architecture-generator" data-astro-cid-ssfzsv2f>ai architecture generator</a> <a class="sb-all" href="/tools?cat=ai" data-astro-cid-ssfzsv2f>All AI tools →</a> </div> </div> <div class="sb-sec" data-sec="lessons" data-astro-cid-ssfzsv2f> <button class="sb-toggle" type="button" aria-expanded="false" data-astro-cid-ssfzsv2f><span class="sb-ic" data-astro-cid-ssfzsv2f><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 4 2 9l10 5 10-5-10-5Z"/><path d="M6 11v5c0 1.1 2.7 2.5 6 2.5s6-1.4 6-2.5v-5"/></svg></span><span class="sb-lbl" data-astro-cid-ssfzsv2f>Learning paths</span><span class="sb-chev" data-astro-cid-ssfzsv2f><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><path d="m6 9 6 6 6-6"/></svg></span></button> <div class="sb-list" data-astro-cid-ssfzsv2f> <a class="sb-link" href="/learn-ai-infrastructure" data-astro-cid-ssfzsv2f>AI Infrastructure</a><a class="sb-link" href="/learn-ai-agents" data-astro-cid-ssfzsv2f>Build AI Agents</a><a class="sb-link" href="/learn-prompting" data-astro-cid-ssfzsv2f>Master Prompting</a><a class="sb-link" href="/learn-ai-automation" data-astro-cid-ssfzsv2f>Automate Work</a><a class="sb-link" href="/learn-ai-coding" data-astro-cid-ssfzsv2f>Coding with AI</a> <a class="sb-link" href="/skill-tree" data-astro-cid-ssfzsv2f>Skill Tree</a> <a class="sb-all" href="/learn" data-astro-cid-ssfzsv2f>All learning paths →</a> </div> </div> <div class="sb-sec" data-sec="refs" data-astro-cid-ssfzsv2f> <button class="sb-toggle" type="button" aria-expanded="false" data-astro-cid-ssfzsv2f><span class="sb-ic" data-astro-cid-ssfzsv2f><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="round"><path d="M14 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8z"/><path d="M14 3v5h5M9 13h6M9 17h6"/></svg></span><span class="sb-lbl" data-astro-cid-ssfzsv2f>References</span><span class="sb-chev" data-astro-cid-ssfzsv2f><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><path d="m6 9 6 6 6-6"/></svg></span></button> <div class="sb-list" data-astro-cid-ssfzsv2f> <a class="sb-link" href="/object-oriented-programming-concepts" data-astro-cid-ssfzsv2f>Object-Oriented Programming concepts</a><a class="sb-link" href="/software-design-patterns" data-astro-cid-ssfzsv2f>Software design patterns</a><a class="sb-link" href="/multithreading-explained" data-astro-cid-ssfzsv2f>Multithreading &amp; concurrency explained</a><a class="sb-link" href="/memory-leaks-explained" data-astro-cid-ssfzsv2f>Memory leaks explained</a><a class="sb-link" href="/smart-pointers-explained" data-astro-cid-ssfzsv2f>Smart pointers &amp; RAII</a><a class="sb-link" href="/cpp-type-casting" data-astro-cid-ssfzsv2f>Type casting in C++</a><a class="sb-link on" href="/csharp" data-astro-cid-ssfzsv2f>C# (C-sharp)</a><a class="sb-link" href="/what-is-json" data-astro-cid-ssfzsv2f>What is JSON?</a><a class="sb-link" href="/what-is-xml" data-astro-cid-ssfzsv2f>What is XML?</a><a class="sb-link" href="/what-is-rss" data-astro-cid-ssfzsv2f>What is RSS?</a><a class="sb-link" href="/what-is-dns" data-astro-cid-ssfzsv2f>What is DNS?</a><a class="sb-link" href="/what-is-whois" data-astro-cid-ssfzsv2f>What is WHOIS?</a><a class="sb-link" href="/http-explained" data-astro-cid-ssfzsv2f>HTTP explained</a><a class="sb-link" href="/how-smtp-works" data-astro-cid-ssfzsv2f>How SMTP works (sending email)</a><a class="sb-link" href="/pop3-vs-imap" data-astro-cid-ssfzsv2f>POP3 vs IMAP (reading email)</a><a class="sb-link" href="/email-deliverability" data-astro-cid-ssfzsv2f>Why your email goes to spam (deliverability)</a><a class="sb-link" href="/dmarc-explained" data-astro-cid-ssfzsv2f>DMARC explained</a><a class="sb-link" href="/spf-explained" data-astro-cid-ssfzsv2f>SPF explained</a><a class="sb-link" href="/dkim-explained" data-astro-cid-ssfzsv2f>DKIM explained</a><a class="sb-link" href="/how-ping-works" data-astro-cid-ssfzsv2f>How ping &amp; ICMP work</a><a class="sb-link" href="/port-scanning-explained" data-astro-cid-ssfzsv2f>Port scanning explained</a><a class="sb-link" href="/shell-scripting-explained" data-astro-cid-ssfzsv2f>Shell scripting explained</a><a class="sb-link" href="/cron-explained" data-astro-cid-ssfzsv2f>Cron explained</a><a class="sb-link" href="/how-to-start-css" data-astro-cid-ssfzsv2f>How to start CSS</a><a class="sb-link" href="/build-an-agentic-os" data-astro-cid-ssfzsv2f>Build your own agentic OS</a><a class="sb-link" href="/git-version-control" data-astro-cid-ssfzsv2f>Git and version control</a><a class="sb-link" href="/monetize-youtube-with-ai" data-astro-cid-ssfzsv2f>Monetize a YouTube channel with AI</a> <a class="sb-all" href="/reference" data-astro-cid-ssfzsv2f>All references →</a> </div> </div> <div class="sb-foot" data-astro-cid-ssfzsv2f> <a class href="/flashcards" title="Flashcards" data-astro-cid-ssfzsv2f><span class="sb-ic" data-astro-cid-ssfzsv2f><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="round"><rect x="3" y="7" width="13" height="14" rx="2"/><path d="M8 7V5a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v11a2 2 0 0 1-2 2h-2"/></svg></span><span class="sb-lbl" data-astro-cid-ssfzsv2f>Flashcards</span><span class="sb-new" data-astro-cid-ssfzsv2f>New</span></a> <a class href="/til" title="Today I Learned" data-astro-cid-ssfzsv2f><span class="sb-ic" data-astro-cid-ssfzsv2f><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="round"><path d="M14 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8z"/><path d="M14 3v5h5M9 13h6M9 17h6"/></svg></span><span class="sb-lbl" data-astro-cid-ssfzsv2f>Today I Learned</span><span class="sb-new" data-astro-cid-ssfzsv2f>New</span></a> <a class href="/resources" title="Free resources" data-astro-cid-ssfzsv2f><span class="sb-ic" data-astro-cid-ssfzsv2f><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="round"><rect x="3" y="7" width="18" height="13" rx="2"/><path d="M8 7V5a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2M3 13h18"/></svg></span><span class="sb-lbl" data-astro-cid-ssfzsv2f>Free resources</span><span class="sb-new" data-astro-cid-ssfzsv2f>New</span></a> <a class href="/map" title="Knowledge map" data-astro-cid-ssfzsv2f><span class="sb-ic" data-astro-cid-ssfzsv2f><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="round"><path d="M9 3 3 5v16l6-2 6 2 6-2V3l-6 2-6-2Z"/><path d="M9 3v16M15 5v16"/></svg></span><span class="sb-lbl" data-astro-cid-ssfzsv2f>Knowledge map</span></a> </div> </aside>  <script>
  (function () {
    const sb = document.getElementById('kb-sb'); if (!sb) return;
    const ls = { get: (k) => { try { return localStorage.getItem(k); } catch { return null; } }, set: (k, v) => { try { localStorage.setItem(k, v); } catch {} } };

    // overall collapse to icon rail (desktop), remembered. Class lives on the sidebar.
    if (ls.get('kb-sb-collapsed') === '1') sb.classList.add('collapsed');
    const collapseBtn = document.getElementById('sb-collapse');
    if (collapseBtn) collapseBtn.addEventListener('click', () => {
      const on = sb.classList.toggle('collapsed'); ls.set('kb-sb-collapsed', on ? '1' : '0');
    });

    // expandable sections, remembered
    sb.querySelectorAll('.sb-sec').forEach(sec => {
      const key = 'kb-sb-' + sec.dataset.sec;
      const saved = ls.get(key);
      // every section stays tucked by default; opens only if the user expanded it before
      if (saved === '1') sec.classList.add('open');
      const btn = sec.querySelector('.sb-toggle');
      btn.setAttribute('aria-expanded', sec.classList.contains('open'));
      btn.addEventListener('click', () => {
        // if collapsed to the rail, expand the rail first so the list is visible
        if (sb.classList.contains('collapsed') && window.innerWidth > 900) { sb.classList.remove('collapsed'); ls.set('kb-sb-collapsed', '0'); }
        const open = sec.classList.toggle('open'); ls.set(key, open ? '1' : '0'); btn.setAttribute('aria-expanded', open);
      });
    });

    // keep the drawer docked just under the sticky header (measured, so it adapts to header height)
    const setNavH = () => { const nav = document.querySelector('.site-nav'); if (nav) document.documentElement.style.setProperty('--kb-navh', nav.offsetHeight + 'px'); };
    setNavH(); window.addEventListener('resize', setNavH);

    // mobile drawer
    const burger = document.getElementById('sb-burger');
    const syncBurger = (open) => { if (burger) { burger.classList.toggle('open', open); burger.setAttribute('aria-expanded', open ? 'true' : 'false'); burger.setAttribute('aria-label', open ? 'Close menu' : 'Open menu'); } };
    const closeDrawer = () => { sb.classList.remove('drawer-open'); document.getElementById('sb-overlay') && document.getElementById('sb-overlay').classList.remove('on'); syncBurger(false); };
    if (burger) burger.addEventListener('click', () => {
      setNavH();
      const open = sb.classList.toggle('drawer-open');
      const ov = document.getElementById('sb-overlay'); if (ov) ov.classList.toggle('on', open);
      syncBurger(open);
    });
    const ov = document.getElementById('sb-overlay'); if (ov) ov.addEventListener('click', closeDrawer);
    const closeBtn = document.getElementById('sb-close'); if (closeBtn) closeBtn.addEventListener('click', closeDrawer);
    document.addEventListener('keydown', (e) => { if (e.key === 'Escape' && sb.classList.contains('drawer-open')) closeDrawer(); });
    sb.querySelectorAll('a').forEach(a => a.addEventListener('click', () => { if (window.innerWidth <= 900) closeDrawer(); }));
  })();
</script> <main class="layout-main"> <nav class="crumb" aria-label="Breadcrumb"> <a href="/">KB Cafe</a> <span>/</span><a href="/reference">Knowledge Base</a><span>/</span><em>C# (C-sharp)</em> </nav>  <article class="ref-article"> <header class="ref-head"> <div class="eyebrow">Knowledge Base · C#</div> <h1>C# (C-sharp)</h1> <p class="tagline">C# is Microsoft&#39;s modern, statically-typed language on the .NET platform. Here&#39;s what it is, how it relates to .NET, and the features that define it, with code.</p> </header> <div class="prose">  <nav class="toc" aria-label="On this page"> <span class="toc-h">On this page</span> <a href="#what">What C# is</a> <a href="#dotnet">C# &amp; .NET</a> <a href="#features">Signature features</a> <a href="#code">In code</a> <a href="#vs">C# vs Java vs C++</a> <a href="#faq">FAQ</a> </nav> <h2 id="what">What C# is</h2> <p> <strong>C# (&ldquo;C-sharp&rdquo;)</strong> is a statically-typed, object-oriented language created by Microsoft
    and first released in 2000. It is <strong>compiled, garbage-collected, and strongly tooled</strong>, and today
    it is fully <strong>cross-platform</strong>: the same C# runs on Windows, macOS, and Linux, and targets web,
    desktop, cloud, mobile, and games (it&rsquo;s the language of the Unity engine). It pairs C-family syntax with
    high-level features that keep it productive without dropping to manual memory management.
</p> <h2 id="dotnet">C# &amp; .NET</h2> <p>
A common point of confusion: <strong>C# is the language; .NET is the platform it runs on.</strong> You write
    C#, the compiler turns it into an <strong>intermediate language (IL)</strong>, and the .NET runtime (the CLR)
    executes that IL, compiling it to native code just in time. .NET also provides the standard library and tooling.
    Modern <strong>.NET</strong> (the successor to the Windows-only .NET Framework) is open-source and cross-platform;
    other languages like F# target the same runtime.
</p> <h2 id="features">Signature features</h2> <ul> <li><strong>Strong, static typing</strong> with rich type inference (<code>var</code>) and, since C# 8,
<strong>nullable reference types</strong> that surface null bugs at compile time.</li> <li><strong>LINQ</strong>: declarative queries (filter/project/group/join) over any sequence with one syntax.</li> <li><strong>async/await</strong>: non-blocking asynchronous code that reads sequentially.</li> <li><strong>Generics</strong>: type-safe reusable containers and algorithms without casting.</li> <li><strong>Records &amp; value types</strong>: concise immutable data types with value equality.</li> <li><strong>Properties, pattern matching, and first-class delegates/events</strong> for clean
<a href="/object-oriented-programming-concepts">object-oriented</a> and event-driven code.</li> </ul> <h2 id="code">In code</h2> <pre class="code"><code>// Modern C#: records, LINQ, async/await, nullable reference types
public record Dev(string Name, int CommitsThisYear);

var team = new List&lt;Dev&gt; {
    new("Ada", 412),
    new("Linus", 1290),
    new("Grace", 88),
};

// LINQ: declarative queries over any sequence
var prolific = team
    .Where(d =&gt; d.CommitsThisYear &gt; 100)
    .OrderByDescending(d =&gt; d.CommitsThisYear)
    .Select(d =&gt; d.Name);

// async/await: non-blocking I/O without callbacks
async Task&lt;string&gt; FetchAsync(HttpClient http, string url) {
    return await http.GetStringAsync(url);   // frees the thread while waiting
}</code></pre> <h2 id="vs">C# vs Java vs C++</h2> <table class="cmp"> <thead><tr><th></th><th>C#</th><th>Java</th><th>C++</th></tr></thead> <tbody> <tr><td>Memory</td><td>Garbage-collected</td><td>Garbage-collected</td><td>Manual / RAII</td></tr> <tr><td>Runs on</td><td>.NET (CLR)</td><td>JVM</td><td>Native</td></tr> <tr><td>Compiles to</td><td>IL &rarr; JIT native</td><td>Bytecode &rarr; JIT</td><td>Native machine code</td></tr> <tr><td>Signature features</td><td>LINQ, async, records</td><td>Vast ecosystem, portability</td><td>Zero-cost abstractions, control</td></tr> <tr><td>Typical use</td><td>Web, cloud, desktop, Unity</td><td>Enterprise, Android, big data</td><td>Systems, games, performance</td></tr> </tbody> </table> <p>
Coming from C++? The memory model is the biggest shift, see <a href="/smart-pointers-explained">smart pointers
    &amp; RAII</a> and <a href="/memory-leaks-explained">memory leaks</a> for what the garbage collector handles for
    you. The <a href="/object-oriented-programming-concepts">OOP concepts</a> and
<a href="/software-design-patterns">design patterns</a> carry straight over.
</p> <h2 id="faq">FAQ</h2> <details class="faq"><summary>What is C# and who made it?</summary><p>C# (pronounced &#39;C-sharp&#39;) is a statically-typed, object-oriented language created by Microsoft, first released in 2000, with Anders Hejlsberg as lead designer. It runs on the .NET platform and is used for web apps (ASP.NET), desktop, games (Unity), cloud services, and tooling.</p></details><details class="faq"><summary>What is the difference between C# and .NET?</summary><p>C# is the language; .NET is the platform it runs on, the runtime (CLR), the standard libraries, and the tooling. You write C#, it compiles to an intermediate language (IL), and the .NET runtime executes it. Other languages (F#, VB.NET) also target .NET.</p></details><details class="faq"><summary>Is C# cross-platform?</summary><p>Yes. Since .NET Core (now just &#39;.NET&#39;), C# runs on Windows, macOS, and Linux, and compiles for mobile and WebAssembly. The old Windows-only .NET Framework still exists for legacy apps, but new work targets modern cross-platform .NET.</p></details><details class="faq"><summary>C# vs Java, how different are they?</summary><p>They are close cousins: both statically typed, object-oriented, garbage-collected, and compiled to a bytecode/IL run on a managed runtime. C# tends to adopt language features faster (LINQ, value types/records, properties, async/await came earlier, nullable reference types). Day to day, someone fluent in one reads the other easily.</p></details><details class="faq"><summary>What is LINQ?</summary><p>Language Integrated Query: a set of language features and methods for writing declarative queries (filter, project, group, join) over any sequence, in-memory collections, databases, XML, with the same syntax. It is one of C#&#39;s signature features.</p></details><details class="faq"><summary>What does async/await do in C#?</summary><p>It lets you write non-blocking asynchronous code that reads like sequential code. An awaited operation (usually I/O) frees the current thread to do other work until the result is ready, instead of blocking it. It is the standard way to keep apps responsive and servers scalable.</p></details><details class="faq"><summary>Is C# a good language to learn in 2026?</summary><p>Yes. It is mature, consistently modern, strongly tooled (Visual Studio, Rider, VS Code), and spans web, cloud, desktop, and game development (Unity). Its concepts, OOP, generics, async, also transfer directly to other mainstream languages.</p></details><div class="classic"> <span class="classic-tag">☕ KB Cafe Classic</span> <p>
C# and .NET are core to KB Cafe&rsquo;s DNA, the original site was a working C#/.NET reference back when the
      language was new and developers were migrating from C++ and classic ASP. This is the modern restoration:
      what C# is now, cross-platform and several language generations on, with the fundamentals that still define it.
</p> </div> <script type="application/ld+json">{"@context":"https://schema.org","@type":"FAQPage","mainEntity":[{"@type":"Question","name":"What is C# and who made it?","acceptedAnswer":{"@type":"Answer","text":"C# (pronounced 'C-sharp') is a statically-typed, object-oriented language created by Microsoft, first released in 2000, with Anders Hejlsberg as lead designer. It runs on the .NET platform and is used for web apps (ASP.NET), desktop, games (Unity), cloud services, and tooling."}},{"@type":"Question","name":"What is the difference between C# and .NET?","acceptedAnswer":{"@type":"Answer","text":"C# is the language; .NET is the platform it runs on, the runtime (CLR), the standard libraries, and the tooling. You write C#, it compiles to an intermediate language (IL), and the .NET runtime executes it. Other languages (F#, VB.NET) also target .NET."}},{"@type":"Question","name":"Is C# cross-platform?","acceptedAnswer":{"@type":"Answer","text":"Yes. Since .NET Core (now just '.NET'), C# runs on Windows, macOS, and Linux, and compiles for mobile and WebAssembly. The old Windows-only .NET Framework still exists for legacy apps, but new work targets modern cross-platform .NET."}},{"@type":"Question","name":"C# vs Java, how different are they?","acceptedAnswer":{"@type":"Answer","text":"They are close cousins: both statically typed, object-oriented, garbage-collected, and compiled to a bytecode/IL run on a managed runtime. C# tends to adopt language features faster (LINQ, value types/records, properties, async/await came earlier, nullable reference types). Day to day, someone fluent in one reads the other easily."}},{"@type":"Question","name":"What is LINQ?","acceptedAnswer":{"@type":"Answer","text":"Language Integrated Query: a set of language features and methods for writing declarative queries (filter, project, group, join) over any sequence, in-memory collections, databases, XML, with the same syntax. It is one of C#'s signature features."}},{"@type":"Question","name":"What does async/await do in C#?","acceptedAnswer":{"@type":"Answer","text":"It lets you write non-blocking asynchronous code that reads like sequential code. An awaited operation (usually I/O) frees the current thread to do other work until the result is ready, instead of blocking it. It is the standard way to keep apps responsive and servers scalable."}},{"@type":"Question","name":"Is C# a good language to learn in 2026?","acceptedAnswer":{"@type":"Answer","text":"Yes. It is mature, consistently modern, strongly tooled (Visual Studio, Rider, VS Code), and spans web, cloud, desktop, and game development (Unity). Its concepts, OOP, generics, async, also transfer directly to other mainstream languages."}}]}</script>  </div> </article> <aside class="share subtle t-caption" data-share data-treat="caption" data-astro-cid-ung7bpju>  <span class="share-cap" data-astro-cid-ung7bpju>Share this page</span> <div class="share-btns" data-astro-cid-ung7bpju> <button class="sh sh-launch js-nativeshare" type="button" data-title="C# (C-sharp)" aria-label="Share this page" title="Share this page" data-astro-cid-ung7bpju><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.1" stroke-linecap="round" stroke-linejoin="round"><path d="M4 12v7a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-7"/><path d="M16 6l-4-4-4 4"/><path d="M12 2v13"/></svg></button>   <a class="sh tone-x" href="https://x.com/intent/tweet?text=C%23%20(C-sharp)%2C%20on%20KB%20Cafe&amp;url=https%3A%2F%2Fkbcafe.com%2Fcsharp" target="_blank" rel="noopener noreferrer" aria-label="Share on X" title="Share on X" data-astro-cid-ung7bpju><svg viewBox="0 0 24 24" fill="currentColor"><path d="M18.9 2H22l-7.3 8.3L23 22h-6.6l-5.2-6.8L5.3 22H2l7.8-8.9L1.7 2h6.8l4.7 6.2L18.9 2Zm-1.2 18h1.8L7.2 3.8H5.3L17.7 20Z"/></svg></a><a class="sh tone-reddit" href="https://www.reddit.com/submit?url=https%3A%2F%2Fkbcafe.com%2Fcsharp&amp;title=C%23%20(C-sharp)" target="_blank" rel="noopener noreferrer" aria-label="Share on Reddit" title="Share on Reddit" data-astro-cid-ung7bpju><svg viewBox="0 0 24 24" fill="currentColor"><path d="M22 12.1a2.1 2.1 0 0 0-3.6-1.5 10.3 10.3 0 0 0-5.3-1.7l.9-4.1 2.9.6a1.5 1.5 0 1 0 .2-1l-3.3-.7a.5.5 0 0 0-.6.4l-1 4.8a10.4 10.4 0 0 0-5.4 1.7 2.1 2.1 0 1 0-2.3 3.4 4 4 0 0 0 0 .6c0 3.1 3.6 5.6 8 5.6s8-2.5 8-5.6a4 4 0 0 0 0-.6 2.1 2.1 0 0 0 1.4-2Zm-13 1.4a1.4 1.4 0 1 1 1.4 1.4 1.4 1.4 0 0 1-1.4-1.4Zm7.8 3.6a5.2 5.2 0 0 1-3.8 1.2 5.2 5.2 0 0 1-3.8-1.2.5.5 0 0 1 .7-.7 4.3 4.3 0 0 0 3.1.9 4.3 4.3 0 0 0 3.1-.9.5.5 0 1 1 .7.7Zm-.3-2.2a1.4 1.4 0 1 1 1.4-1.4 1.4 1.4 0 0 1-1.4 1.4Z"/></svg></a><a class="sh tone-linkedin" href="https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fkbcafe.com%2Fcsharp" target="_blank" rel="noopener noreferrer" aria-label="Share on LinkedIn" title="Share on LinkedIn" data-astro-cid-ung7bpju><svg viewBox="0 0 24 24" fill="currentColor"><path d="M6.94 5a2 2 0 1 1-4 0 2 2 0 0 1 4 0ZM3.3 8.4h3.3V21H3.3V8.4Zm5.5 0H12v1.7h.05a3.5 3.5 0 0 1 3.15-1.7c3.4 0 4 2.2 4 5.1V21h-3.3v-5.6c0-1.3 0-3-1.85-3s-2.1 1.4-2.1 2.9V21H8.8V8.4Z"/></svg></a><a class="sh tone-facebook" href="https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fkbcafe.com%2Fcsharp" target="_blank" rel="noopener noreferrer" aria-label="Share on Facebook" title="Share on Facebook" data-astro-cid-ung7bpju><svg viewBox="0 0 24 24" fill="currentColor"><path d="M22 12a10 10 0 1 0-11.56 9.88v-6.99H7.9V12h2.54V9.8c0-2.5 1.49-3.89 3.78-3.89 1.09 0 2.24.2 2.24.2v2.46h-1.26c-1.24 0-1.63.77-1.63 1.56V12h2.78l-.44 2.89h-2.34v6.99A10 10 0 0 0 22 12Z"/></svg></a><a class="sh tone-mail" href="mailto:?subject=C%23%20(C-sharp)&amp;body=C%23%20(C-sharp)%2C%20on%20KB%20Cafe%20https%3A%2F%2Fkbcafe.com%2Fcsharp" aria-label="Share by email" title="Share by email" data-astro-cid-ung7bpju><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linejoin="round"><rect x="3" y="5" width="18" height="14" rx="2.5"/><path d="m3 7 9 6 9-6"/></svg></a><button class="sh tone-link js-copylink" type="button" data-discord aria-label="Copy link for Discord" title="Copy link for Discord" data-astro-cid-ung7bpju><svg viewBox="0 0 24 24" fill="currentColor"><path d="M19.3 5.3A16 16 0 0 0 15.4 4l-.25.5a12 12 0 0 1 3.4 1.1 11 11 0 0 0-9.1 0A12 12 0 0 1 12.9 4.5L12.6 4a16 16 0 0 0-3.9 1.3C5.2 8.7 4.6 12 4.8 15.2a16 16 0 0 0 4.8 2.4l.6-1a10 10 0 0 1-1.6-.8l.4-.3a8.4 8.4 0 0 0 7.2 0l.4.3a10 10 0 0 1-1.6.8l.6 1a16 16 0 0 0 4.8-2.4c.3-3.7-.6-7-2.3-9.9ZM9.7 13.5c-.8 0-1.4-.7-1.4-1.6s.6-1.6 1.4-1.6 1.4.7 1.4 1.6-.6 1.6-1.4 1.6Zm4.6 0c-.8 0-1.4-.7-1.4-1.6s.6-1.6 1.4-1.6 1.4.7 1.4 1.6-.6 1.6-1.4 1.6Z"/></svg></button><button class="sh tone-link js-copylink" type="button" aria-label="Copy link" title="Copy link" data-astro-cid-ung7bpju><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round"><path d="M9 15 15 9M10.5 6.5l1-1a4 4 0 0 1 6 6l-1 1M13.5 17.5l-1 1a4 4 0 0 1-6-6l1-1"/></svg></button> <span class="share-done" hidden data-astro-cid-ung7bpju>Link copied</span> </div> </aside>  <script type="module">function i(a,t){const e=a.closest("[data-share]")?.querySelector(".share-done");e&&(e.textContent=t,e.hidden=!1,setTimeout(()=>{e.hidden=!0},2400))}window.__kbShareInit||(window.__kbShareInit=!0,document.addEventListener("click",async a=>{const t=a.target.closest(".js-copylink");if(t){try{await navigator.clipboard.writeText(location.href)}catch{}i(t,t.hasAttribute("data-discord")?"Page URL copied, open Discord to share.":"Link copied")}}),document.addEventListener("click",async a=>{const t=a.target.closest(".js-nativeshare");if(!t)return;const e=location.href,r=t.getAttribute("data-title")||document.title;try{navigator.share?await navigator.share({title:r,url:e}):navigator.clipboard&&(await navigator.clipboard.writeText(e),i(t,"Link copied"))}catch{}}));</script> <div class="qs" id="qs-block" hidden> <div class="qs-l"><span class="qs-score" id="qs-score"></span> <span class="qs-cta">Think your friends can beat it?</span></div> <div class="qs-btns"> <button class="qs-b qs-native" type="button" id="qs-native">&#8599; Challenge a friend</button> <a class="qs-b" id="qs-x" target="_blank" rel="noopener">Post on X</a> <a class="qs-b" id="qs-reddit" target="_blank" rel="noopener">Reddit</a> <button class="qs-b" type="button" id="qs-copy">Copy link</button> </div> </div>  <script>(function(){const url = "https://kbcafe.com/csharp";
const title = "C# (C-sharp)";

  window.__kbQuizShare = function (correct, total, quizId, label) {
    var block = document.getElementById('qs-block'); if (!block) return;
    var quiz = quizId && document.getElementById(quizId);
    if (quiz && quiz.parentNode) quiz.insertAdjacentElement('afterend', block);
    var link = url + (quizId ? '#' + quizId : '');
    document.getElementById('qs-score').textContent = 'You got ' + correct + '/' + total + '.';
    var shareText = 'I scored ' + correct + '/' + total + ' on ' + (label || title) + ' at KB Cafe. Can you beat it?';
    var u = encodeURIComponent(link), t = encodeURIComponent(shareText);
    document.getElementById('qs-x').href = 'https://x.com/intent/tweet?text=' + t + '&url=' + u;
    document.getElementById('qs-reddit').href = 'https://www.reddit.com/submit?url=' + u + '&title=' + t;
    block.hidden = false;
    var nat = document.getElementById('qs-native');
    nat.onclick = function () {
      if (navigator.share) { navigator.share({ title: title, text: shareText, url: link }).catch(function () {}); }
      else { navigator.clipboard.writeText(link).then(function () { nat.textContent = 'Link copied'; }).catch(function () {}); }
    };
    var cp = document.getElementById('qs-copy');
    cp.onclick = function () { navigator.clipboard.writeText(link).then(function () { cp.textContent = 'Copied'; setTimeout(function () { cp.textContent = 'Copy link'; }, 1500); }).catch(function () {}); };
  };
})();</script> <aside class="cont" aria-label="Keep going"><a class="cont-resume" id="cont-resume" href="#" hidden></a><div class="cont-h">Keep going</div><a class="cont-next" href="/object-oriented-programming-concepts"><span class="cont-next-l"><span class="cont-eye">Read this next</span><span class="cont-next-t">Object-Oriented Programming concepts</span><span class="cont-next-d">Encapsulation, abstraction, inheritance, polymorphism, the four pillars, with examples.</span></span><span class="cont-next-ar" aria-hidden="true">&rarr;</span></a><div class="cont-grid"><a class="cont-gcard" href="/software-design-patterns"><span class="cont-gtag">Concepts</span><span class="cont-gq">Software design patterns</span><span class="cont-gd">The classic Gang-of-Four patterns, creational, structural, behavioral, and when to use them.</span><span class="cont-ggo" aria-hidden="true">&rarr;</span></a><a class="cont-gcard" href="/multithreading-explained"><span class="cont-gtag">Concurrency</span><span class="cont-gq">Multithreading & concurrency explained</span><span class="cont-gd">Threads vs processes, race conditions, locks, deadlocks, and writing thread-safe code.</span><span class="cont-ggo" aria-hidden="true">&rarr;</span></a></div></aside><script>(function(){const pathsLite = [{"title":"AI Infrastructure","route":"/learn-ai-infrastructure","steps":["/what-is-a-context-window","/token-counter","/what-are-embeddings","/embedding-explorer","/what-is-a-vector-database","/what-is-rag","/rag-chunking-visualizer"],"titles":["What is a context window?","/token-counter","What are embeddings?","/embedding-explorer","What is a vector database?","What is RAG (Retrieval-Augmented Generation)?","/rag-chunking-visualizer"]},{"title":"Build AI Agents","route":"/learn-ai-agents","steps":["/how-to-build-an-ai-agent","/what-is-tool-calling","/tool-call-visualizer","/what-are-structured-outputs","/structured-output-builder","/ai-patterns","/ai-pattern-builder","/what-is-agent-memory","/agent-memory-simulator","/what-is-mcp","/what-are-mcp-servers","/mcp-config-generator","/ai-architecture-generator"],"titles":["How to build an AI agent","What is tool calling (function calling)?","/tool-call-visualizer","What are structured outputs?","Structured Output Builder","AI Patterns Library","/ai-pattern-builder","What is agent memory?","/agent-memory-simulator","What is MCP (Model Context Protocol)?","What are MCP servers?","/mcp-config-generator","/ai-architecture-generator"]},{"title":"Master Prompting","route":"/learn-prompting","steps":["/prompt-simulator","/prompt-builder","/prompt-x-ray","/prompt-linter","/prompt-diff","/good-vs-bad-prompts","/prompt-optimizer"],"titles":["/prompt-simulator","/prompt-builder","/prompt-x-ray","/prompt-linter","/prompt-diff","/good-vs-bad-prompts","/prompt-optimizer"]},{"title":"Automate Work","route":"/learn-ai-automation","steps":["/what-is-workflow-automation","/automation-blueprints","/cron-generator","/webhooks-vs-polling","/ai-agents-vs-workflows-vs-rpa","/what-is-tool-calling","/tool-call-visualizer","/what-is-ai-orchestration","/what-are-ai-loops","/ai-architecture-generator"],"titles":["What is workflow automation?","Automation Blueprint Explorer","/cron-generator","Webhooks vs polling","AI agents vs workflows vs RPA","What is tool calling (function calling)?","/tool-call-visualizer","What is AI orchestration?","What are AI loops?","/ai-architecture-generator"]},{"title":"Coding with AI","route":"/learn-ai-coding","steps":["/how-to-write-code-with-ai","/ai-coding-prompt-builder","/what-is-a-context-window","/context-window-visualizer","/what-is-tool-calling"],"titles":["How to write code with AI","AI Coding Prompt Builder","What is a context window?","Context Window Visualizer","What is tool calling (function calling)?"]}];

  (function () {
    // #4 recall: shuffle options, grade, reveal flashcards CTA
    var rc = document.getElementById('cont-recall');
    if (rc) {
      var opts = document.getElementById('cont-opts');
      var kids = Array.prototype.slice.call(opts.children);
      for (var i = kids.length - 1; i > 0; i--) { var j = Math.floor(Math.random() * (i + 1)); opts.appendChild(kids[j]); kids.splice(j, 1); kids.push(opts.lastChild); }
      opts.addEventListener('click', function (e) {
        var b = e.target.closest('.cont-opt'); if (!b || b.disabled) return;
        var ok = b.dataset.ok === '1';
        Array.prototype.forEach.call(opts.children, function (c) { c.disabled = true; if (c.dataset.ok === '1') c.classList.add('right'); else if (c === b) c.classList.add('wrong'); });
        var cta = document.getElementById('cont-recall-cta');
        document.getElementById('cont-recall-msg').textContent = ok ? 'Nailed it. Lock the rest in.' : 'Worth a review, drill the deck.';
        cta.hidden = false;
      });
    }
    // #5 resume: most-progressed unfinished path, next unread step
    try {
      var read = new Set(JSON.parse(localStorage.getItem('kbcafe-progress') || '[]'));
      if (read.size >= 2) {
        var best = null;
        pathsLite.forEach(function (p) {
          var n = p.steps.filter(function (s) { return read.has(s); }).length;
          if (n > 0 && n < p.steps.length && (!best || n > best.n)) {
            var ni = p.steps.findIndex(function (s) { return !read.has(s); });
            best = { n: n, total: p.steps.length, title: p.title, nextHref: p.steps[ni], nextTitle: (p.titles[ni] || '').replace(/<[^>]+>/g, '') };
          }
        });
        if (best && best.nextHref) {
          var el = document.getElementById('cont-resume');
          el.href = best.nextHref;
          el.innerHTML = '<span><span class="rt">Welcome back, you are ' + best.n + ' of ' + best.total + ' through ' + best.title + '.</span><span class="rd">Next: ' + best.nextTitle + '</span></span><span class="rb">Resume &rarr;</span>';
          el.hidden = false;
        }
      }
    } catch (e) {}
  })();
})();</script> <script>
  (function () {
    var prose = document.querySelector('.prose');
    if (!prose) return;

    // ── read-time chip ───────────────────────────────────────────────
    var words = (prose.innerText || '').trim().split(/\s+/).filter(Boolean).length;
    if (words > 150) {
      var mins = Math.max(1, Math.round(words / 220));
      var chip = document.createElement('div');
      chip.className = 'read-meta';
      chip.innerHTML = '<span class="rm-dot"></span>' + mins + ' min read';
      prose.insertBefore(chip, prose.firstChild);
    }

    // ── scroll-progress bar (overall page scroll) ────────────────────
    var bar = document.createElement('div');
    bar.className = 'read-progress';
    var fill = document.createElement('i');
    bar.appendChild(fill);
    document.body.appendChild(bar);
    function updateBar() {
      var h = document.documentElement.scrollHeight - window.innerHeight;
      var p = h > 0 ? window.scrollY / h : 0;
      fill.style.width = (Math.min(1, Math.max(0, p)) * 100) + '%';
    }

    // ── READ detection at ~70% of the article (kbProgress) ───────────
    var marked = false;
    function tryMark() {
      if (marked) return;
      var target = prose.offsetTop + prose.offsetHeight * 0.7;
      if (window.scrollY + window.innerHeight >= target) {
        marked = true;
        try {
          var here = location.pathname.replace(/\/+$/, '') || '/';
          if (window.kbProgress) window.kbProgress.set(here, true);
          if (window.__kbPathNavRender) window.__kbPathNavRender();
        } catch (e) {}
      }
    }

    window.addEventListener('scroll', function () { updateBar(); tryMark(); }, { passive: true });
    window.addEventListener('resize', updateBar, { passive: true });
    updateBar();
    setTimeout(tryMark, 5000); // short pages that fit on screen: mark after a dwell

    // ── move the "On this page" TOC into the sticky header centre (wide screens) ──
    var toc = document.querySelector('.toc');
    var navCenter = document.getElementById('nav-center');
    if (toc && navCenter && window.matchMedia('(min-width:920px)').matches) {
      navCenter.appendChild(toc);
    }

    // ── scrollspy: highlight current section in the TOC ──────────────
    if (toc) {
      var links = Array.prototype.slice.call(toc.querySelectorAll('a[href^="#"]'));
      var map = {};
      links.forEach(function (a) {
        var id = decodeURIComponent(a.getAttribute('href').slice(1));
        var t = document.getElementById(id);
        if (t) map[id] = a;
      });
      var ids = Object.keys(map);
      if (ids.length && 'IntersectionObserver' in window) {
        var io = new IntersectionObserver(function (entries) {
          entries.forEach(function (en) {
            if (en.isIntersecting) {
              links.forEach(function (a) { a.classList.remove('is-active'); });
              if (map[en.target.id]) map[en.target.id].classList.add('is-active');
            }
          });
        }, { rootMargin: '-12% 0px -75% 0px', threshold: 0 });
        ids.forEach(function (id) { io.observe(document.getElementById(id)); });
      }
    }

    // ── copy buttons on dark code blocks ─────────────────────────────
    Array.prototype.slice.call(document.querySelectorAll('pre.code')).forEach(function (pre) {
      if (pre.querySelector('.code-copy')) return;
      var btn = document.createElement('button');
      btn.type = 'button';
      btn.className = 'code-copy';
      btn.textContent = 'Copy';
      pre.appendChild(btn);
      btn.addEventListener('click', function () {
        var code = pre.querySelector('code');
        var txt = code ? code.innerText : pre.innerText;
        var done = function () { btn.textContent = 'Copied'; btn.classList.add('ok'); setTimeout(function () { btn.textContent = 'Copy'; btn.classList.remove('ok'); }, 1600); };
        if (navigator.clipboard && navigator.clipboard.writeText) {
          navigator.clipboard.writeText(txt).then(done).catch(function () {});
        } else {
          try { var ta = document.createElement('textarea'); ta.value = txt; document.body.appendChild(ta); ta.select(); document.execCommand('copy'); document.body.removeChild(ta); done(); } catch (e) {}
        }
      });
    });
  })();
</script>   </main> <div class="sb-overlay" id="sb-overlay"></div> </div> <footer> <a class="foot-brand" href="/" aria-label="KB Cafe, home"> <img class="foot-mark" src="/logo.png" width="28" height="28" alt=""> <span>Cafe</span> </a> <nav class="foot-links"> <a href="/about">About</a> <a href="/dictionary">Dictionary</a> <a href="/blog">Blog</a> <a href="/privacy">Privacy</a> <a href="/terms">Terms</a> </nav> <div class="foot-social"> <a href="https://github.com/damnepic/kbcafe" target="_blank" rel="noopener noreferrer" aria-label="GitHub" title="GitHub"><svg width="19" height="19" viewBox="0 0 24 24" fill="currentColor"><path d="M12 2A10 10 0 0 0 8.84 21.5c.5.08.66-.22.66-.48v-1.7c-2.78.6-3.37-1.34-3.37-1.34-.45-1.16-1.1-1.47-1.1-1.47-.9-.62.07-.6.07-.6 1 .07 1.53 1.03 1.53 1.03.9 1.52 2.34 1.08 2.91.83.1-.65.35-1.09.63-1.34-2.22-.25-4.55-1.11-4.55-4.94 0-1.09.39-1.98 1.03-2.68-.1-.25-.45-1.27.1-2.65 0 0 .84-.27 2.75 1.02a9.6 9.6 0 0 1 5 0c1.9-1.29 2.74-1.02 2.74-1.02.55 1.38.2 2.4.1 2.65.64.7 1.03 1.59 1.03 2.68 0 3.84-2.34 4.69-4.57 4.94.36.31.68.92.68 1.85v2.74c0 .27.16.57.67.48A10 10 0 0 0 12 2Z"></path></svg></a> <span class="soon" aria-label="X, coming soon" title="Coming soon"><svg width="17" height="17" viewBox="0 0 24 24" fill="currentColor"><path d="M18.9 2H22l-7.3 8.3L23 22h-6.6l-5.2-6.8L5.3 22H2l7.8-8.9L1.7 2h6.8l4.7 6.2L18.9 2Zm-1.2 18h1.8L7.2 3.8H5.3L17.7 20Z"></path></svg></span> <a href="/feeds" aria-label="Feeds" title="Feeds"><svg width="17" height="17" viewBox="0 0 24 24" fill="currentColor"><circle cx="5" cy="19" r="2.2"></circle><path d="M3 11a10 10 0 0 1 10 10h-3A7 7 0 0 0 3 14v-3Zm0-6a16 16 0 0 1 16 16h-3A13 13 0 0 0 3 8V5Z"></path></svg></a> <a href="/contact" aria-label="Contact" title="Contact"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="5" width="18" height="14" rx="2.5"></rect><path d="m3 7 9 6 9-6"></path></svg></a> </div> <div class="foot-copy">&copy; 1999&ndash;2026 KB Cafe &middot; part of the family with <a href="https://yank.info" target="_blank" rel="noopener noreferrer">yank.info</a></div> </footer> </div> <script>
  // Nav search: ⌘K box on Mac, plain magnifier elsewhere; click/shortcut expands an inline bar.
  (function () {
    var wrap = document.getElementById('navsearch'); if (!wrap) return;
    var toggle = document.getElementById('ns-toggle'), input = document.getElementById('ns-input');
    var isMac = /Mac|iPhone|iPad|iPod/.test(navigator.platform || '') || /Mac OS X|Macintosh/.test(navigator.userAgent || '');
    if (isMac) wrap.classList.add('mac');
    function open() { wrap.classList.add('open'); if (input) input.focus(); }
    function close() { wrap.classList.remove('open'); }
    if (toggle) toggle.addEventListener('click', open);
    if (input) {
      input.addEventListener('keydown', function (e) { if (e.key === 'Escape') { close(); if (toggle) toggle.focus(); } });
      input.addEventListener('blur', function () { if (!input.value) close(); });
    }
    document.addEventListener('keydown', function (e) {
      if ((e.metaKey || e.ctrlKey) && (e.key === 'k' || e.key === 'K')) { e.preventDefault(); open(); }
    });
  })();

  // Study window: an independent, resizable second viewport docked on the right so you can read or use two pages at
  // once. Opens from (1) the nav "Study" toggle, (2) the "Open beside" button by a page title, (3) hovering an
  // in-content link, and (4) arriving from /map (?from=map). Desktop only, entirely JS-injected, so crawled/indexed
  // pages are byte-identical and unaffected (SEO-clean, see the query-stripped canonical).
  (function () {
    function desktop() { return window.innerWidth > 900; }
    function clampW(x) { return Math.max(340, Math.min(Math.round(window.innerWidth * 0.72), x)); }
    function isOpen() { return !!document.querySelector('.kb-maprail-panel'); }
    function syncNav() { var b = document.getElementById('nav-study'); if (b) { b.classList.toggle('on', isOpen()); b.setAttribute('aria-pressed', isOpen() ? 'true' : 'false'); } }

    function build(url) {
      var saved = parseInt(localStorage.getItem('kb-maprail-w') || '', 10);
      var startW = clampW((saved && saved > 0) ? saved : Math.round(Math.min(660, window.innerWidth * 0.46)));
      document.body.style.setProperty('--maprail-w', startW + 'px');
      var nav = document.querySelector('.site-nav'); var navH = nav ? nav.offsetHeight : 64;
      var panel = document.createElement('aside'); panel.className = 'kb-maprail-panel';
      panel.style.top = navH + 'px'; panel.style.height = 'calc(100vh - ' + navH + 'px)';
      panel.innerHTML = '<span class="kb-maprail-grip" title="Drag to resize"></span>'
        + '<div class="kb-maprail-bar"><span class="kb-maprail-title">Study window</span><button class="kb-maprail-close" type="button" aria-label="Close the second window">✕</button></div>'
        + '<iframe class="kb-maprail-frame" title="Study window" loading="lazy"></iframe>';
      document.body.appendChild(panel);
      document.body.classList.add('kb-maprail');
      var frame = panel.querySelector('.kb-maprail-frame'); frame.src = url;
      // reflect whatever page the window is showing (same-origin) so the bar reads as a real window
      var titleEl = panel.querySelector('.kb-maprail-title');
      frame.addEventListener('load', function () {
        try { var t = frame.contentDocument && frame.contentDocument.title; if (t) titleEl.textContent = (t.replace(/\s*[|·:-]\s*KB Cafe.*$/i, '').trim() || t); } catch (e) {}
        persist();   // track the page the window is showing (incl. navigation inside it) so it survives a left-side reload
      });
      // drag the left grip to resize both panes; remember the width
      var grip = panel.querySelector('.kb-maprail-grip');
      grip.addEventListener('pointerdown', function (e) {
        e.preventDefault(); try { grip.setPointerCapture(e.pointerId); } catch (_) {} document.body.classList.add('kb-maprail-drag');
        function mv(ev) { document.body.style.setProperty('--maprail-w', clampW(window.innerWidth - ev.clientX) + 'px'); }
        function up() {
          document.body.classList.remove('kb-maprail-drag');
          grip.removeEventListener('pointermove', mv); grip.removeEventListener('pointerup', up);
          var cur = parseInt(document.body.style.getPropertyValue('--maprail-w'), 10);
          if (cur) { try { localStorage.setItem('kb-maprail-w', cur); } catch (_) {} }
        }
        grip.addEventListener('pointermove', mv); grip.addEventListener('pointerup', up);
      });
      panel.querySelector('.kb-maprail-close').addEventListener('click', closeStudy);
      syncNav();
    }

    // remember the window state (open + the page it is showing) so it survives a left-side reload; SEO-safe (sessionStorage only)
    function persist() {
      var fr = document.querySelector('.kb-maprail-frame'); if (!fr) return;
      var u; try { u = fr.contentWindow.location.pathname + fr.contentWindow.location.search; } catch (e) { u = fr.getAttribute('src'); }
      try { sessionStorage.setItem('kb-study-open', '1'); if (u) sessionStorage.setItem('kb-study-url', u); } catch (e) {}
    }
    function clearPersist() { try { sessionStorage.removeItem('kb-study-open'); sessionStorage.removeItem('kb-study-url'); } catch (e) {} }

    function openStudy(url) {
      if (!desktop()) { location.href = url; return; }   // no split on phones; just navigate there
      var panel = document.querySelector('.kb-maprail-panel');
      if (panel) { panel.querySelector('.kb-maprail-frame').src = url; }
      else { build(url); }
      try { sessionStorage.setItem('kb-study-open', '1'); sessionStorage.setItem('kb-study-url', url); } catch (e) {}
      syncNav();
    }
    function closeStudy() {
      var panel = document.querySelector('.kb-maprail-panel'); if (panel) panel.remove();
      document.body.classList.remove('kb-maprail'); document.body.style.removeProperty('--maprail-w');
      clearPersist();
      syncNav();
    }
    window.openStudyWindow = openStudy;
    window.closeStudyWindow = closeStudy;

    // (1) nav "Study" toggle: open the current page beside, or close if already open
    var navBtn = document.getElementById('nav-study');
    if (navBtn) navBtn.addEventListener('click', function () { isOpen() ? closeStudy() : openStudy(location.pathname + location.search); });

    // (0) RESTORE: a normal link click reloads the whole document, which would drop the right pane. If the window was
    // open on the previous page, re-dock it at the same page, so clicking a left-side link reloads only the left and
    // the right comes back where it was. Pure client JS + sessionStorage, no URL changes, indexed pages unaffected.
    var restored = false;
    if (location.pathname !== '/map' && window.self === window.top && desktop()) {
      var wasOpen = false, savedUrl = null;
      try { wasOpen = sessionStorage.getItem('kb-study-open') === '1'; savedUrl = sessionStorage.getItem('kb-study-url'); } catch (e) {}
      if (wasOpen) { openStudy(savedUrl || '/map'); restored = true; }
    }

    // (4) auto-open when you arrive from /map (?from=map), then strip the param so it never lingers
    if (!restored && location.pathname !== '/map' && window.self === window.top && desktop()) {
      var fromMap = false; try { fromMap = new URLSearchParams(location.search).get('from') === 'map'; } catch (e) {}
      if (fromMap) { openStudy('/map'); try { history.replaceState(null, '', location.pathname + location.hash); } catch (e) {} }
    }

    // (2) "Open beside" button trailing the page title (content pages only)
    if (window.self === window.top && location.pathname !== '/map') {
      var h1 = document.querySelector('.layout-main h1, .tool-head h1, .ref-article h1, .ba h1');
      if (h1 && !document.getElementById('study-beside')) {
        var ob = document.createElement('button'); ob.id = 'study-beside'; ob.className = 'study-beside'; ob.type = 'button';
        ob.title = 'Use this if you want to multi-task or learn with an additional window beside this one, to speed up and enhance your learning experience.';
        ob.setAttribute('aria-label', 'Open this page in a second window. Use it to multi-task or learn with an additional window beside this one, to speed up and enhance your learning experience.');
        ob.innerHTML = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect width="18" height="18" x="3" y="3" rx="2"/><path d="M15 3v18"/><path d="m10 15-3-3 3-3"/></svg><span>Open beside</span>';
        ob.addEventListener('click', function () { openStudy(location.pathname + location.search); });
        h1.appendChild(ob);
      }
    }

    // (3) hover an in-content link to send it to the study window without leaving your place
    if (window.self === window.top) {
      var peek = null, peekHref = null, hideT = null;
      function ensurePeek() {
        if (peek) return peek;
        peek = document.createElement('button'); peek.className = 'kb-linkpeek'; peek.type = 'button';
        peek.innerHTML = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect width="18" height="18" x="3" y="3" rx="2"/><path d="M15 3v18"/></svg>Open in window';
        peek.addEventListener('click', function () { if (peekHref) openStudy(peekHref); hidePeek(); });
        peek.addEventListener('mouseenter', function () { if (hideT) { clearTimeout(hideT); hideT = null; } });
        peek.addEventListener('mouseleave', schedHide);
        document.body.appendChild(peek); return peek;
      }
      function showPeek(a) {
        var p = ensurePeek(), r = a.getBoundingClientRect(); peekHref = a.getAttribute('href');
        p.style.top = (window.scrollY + r.top - 38) + 'px'; p.style.left = (window.scrollX + r.left) + 'px'; p.classList.add('show');
      }
      function hidePeek() { if (peek) peek.classList.remove('show'); }
      function schedHide() { if (hideT) clearTimeout(hideT); hideT = setTimeout(hidePeek, 280); }
      document.addEventListener('mouseover', function (e) {
        var a = e.target.closest && e.target.closest('.prose a[href^="/"], .ba-body a[href^="/"]');
        if (a && desktop()) { if (hideT) { clearTimeout(hideT); hideT = null; } showPeek(a); }
      });
      document.addEventListener('mouseout', function (e) {
        if (e.target.closest && e.target.closest('.prose a[href^="/"], .ba-body a[href^="/"]')) schedHide();
      });
    }
  })();
</script> </body> </html>