{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "eb729e2a",
   "metadata": {},
   "source": [
    "# Think CS in C\\#\n",
    "\n",
    "Welcome to *Think Computer Science in C#*."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d4310861",
   "metadata": {},
   "source": [
    "This book, originally inspired by the work of Andrew N. Harrington and George Thiruvathukal [^1], serves as an introductory computer programming textbook at college level.\n",
    "\n",
    "Designed for students who are formally introduced to programming and computer science for the first time, this book focuses on covering the fundamental concepts of computer science and programming with clarity, structure, and relevance, to help students achieve good understanding of core computing and programming principles.\n",
    "\n",
    "Although modern AI platforms are becoming strong in automated code generation, system engineers, data scientists, and cybersecurity experts with great problem-solving skills will always be needed; and it all begins with the fundamental knowledge of computing and the capability to code."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "45a8cfa5",
   "metadata": {},
   "source": [
    "<h2> C# </h2>\n",
    "\n",
    "Albeit the overall popularity of JavaScript and Python, Java and Microsoft .NET remain as strong technologies for large enterprises. In recent years, especially, Microsoft has made C# the central language for their fast-evolving, open-sourced, and cross-platform .NET ecosystem. \n",
    "\n",
    "C# is a general-purpose, high-level, multiple-paradigm, and is gaining market share as a popular programming language. C# has been used in creating interactive websites, mobile apps, video games, augmented reality (AR) & virtual reality (VR), desktop applications, and back-end services. Specifically, C# is widely used in building cross-platform applications, web services, and game development. For example, the mobile game Pokémon Go is built with the Unity game engine and the Stack Overflow website is built with ASP.NET, and both frameworks use C# as their programming language."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "054bbff3",
   "metadata": {},
   "source": [
    "In the annual Stack Overview Developer Survey[^stack-overflow-survey], for example, C# stays as strong general-purpose languages."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "07c63f21",
   "metadata": {
    "language_info": {
     "name": "polyglot-notebook"
    },
    "polyglot_notebook": {
     "kernelName": "csharp"
    },
    "tags": [
     "remove-input",
     "remove-output"
    ]
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><div></div><div></div><div><strong>Installed Packages</strong><ul><li><span>Microsoft.Data.Analysis, 0.23.0</span></li><li><span>Plotly.NET, 5.1.0</span></li><li><span>Plotly.NET.Interactive, 5.0.0</span></li></ul></div></div>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "Loading extensions from `/Users/tychen/.nuget/packages/plotly.net.interactive/5.0.0/lib/netstandard2.1/Plotly.NET.Interactive.dll`"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "Loading extensions from `/Users/tychen/.nuget/packages/microsoft.data.analysis/0.23.0/interactive-extensions/dotnet/Microsoft.Data.Analysis.Interactive.dll`"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#r \"nuget: Microsoft.Data.Analysis\"\n",
    "#r \"nuget: Plotly.NET\"\n",
    "#r \"nuget: Plotly.NET.Interactive\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "3a9e8d15",
   "metadata": {
    "language_info": {
     "name": "polyglot-notebook"
    },
    "polyglot_notebook": {
     "kernelName": "csharp"
    },
    "tags": [
     "hide-input"
    ]
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><div id=\"114159d1-610f-4ad9-9b6b-57d18c11facd\"><!-- Plotly chart will be drawn inside this DIV --></div><script type=\"text/javascript\">\n",
       "var renderPlotly_114159d1610f4ad99b6b57d18c11facd = function() {\n",
       "    var fsharpPlotlyRequire = requirejs.config({context:'fsharp-plotly',paths:{plotly:'https://cdn.plot.ly/plotly-2.27.1.min'}}) || require;\n",
       "    fsharpPlotlyRequire(['plotly'], function(Plotly) {\n",
       "        var data = [{\"type\":\"bar\",\"name\":\"% Used\",\"x\":[23.3,23.6,27.9,29.5,43.8,48.7,57.9,58.6,61.9,66.0],\"y\":[\"PowerShell\",\"C++\",\"C#\",\"Java\",\"TypeScript\",\"Bash/Shell\",\"Python\",\"SQL\",\"HTML/CSS\",\"JavaScript\"],\"orientation\":\"h\",\"marker\":{\"pattern\":{}}}];\n",
       "        var layout = {\"width\":500,\"height\":320,\"template\":{\"layout\":{\"title\":{\"x\":0.05},\"font\":{\"color\":\"rgba(42, 63, 95, 1.0)\"},\"paper_bgcolor\":\"rgba(255, 255, 255, 1.0)\",\"plot_bgcolor\":\"rgba(229, 236, 246, 1.0)\",\"autotypenumbers\":\"strict\",\"colorscale\":{\"diverging\":[[0.0,\"#8e0152\"],[0.1,\"#c51b7d\"],[0.2,\"#de77ae\"],[0.3,\"#f1b6da\"],[0.4,\"#fde0ef\"],[0.5,\"#f7f7f7\"],[0.6,\"#e6f5d0\"],[0.7,\"#b8e186\"],[0.8,\"#7fbc41\"],[0.9,\"#4d9221\"],[1.0,\"#276419\"]],\"sequential\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]],\"sequentialminus\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]},\"hovermode\":\"closest\",\"hoverlabel\":{\"align\":\"left\"},\"coloraxis\":{\"colorbar\":{\"outlinewidth\":0.0,\"ticks\":\"\"}},\"geo\":{\"showland\":true,\"landcolor\":\"rgba(229, 236, 246, 1.0)\",\"showlakes\":true,\"lakecolor\":\"rgba(255, 255, 255, 1.0)\",\"subunitcolor\":\"rgba(255, 255, 255, 1.0)\",\"bgcolor\":\"rgba(255, 255, 255, 1.0)\"},\"mapbox\":{\"style\":\"light\"},\"polar\":{\"bgcolor\":\"rgba(229, 236, 246, 1.0)\",\"radialaxis\":{\"linecolor\":\"rgba(255, 255, 255, 1.0)\",\"gridcolor\":\"rgba(255, 255, 255, 1.0)\",\"ticks\":\"\"},\"angularaxis\":{\"linecolor\":\"rgba(255, 255, 255, 1.0)\",\"gridcolor\":\"rgba(255, 255, 255, 1.0)\",\"ticks\":\"\"}},\"scene\":{\"xaxis\":{\"ticks\":\"\",\"linecolor\":\"rgba(255, 255, 255, 1.0)\",\"gridcolor\":\"rgba(255, 255, 255, 1.0)\",\"gridwidth\":2.0,\"zerolinecolor\":\"rgba(255, 255, 255, 1.0)\",\"backgroundcolor\":\"rgba(229, 236, 246, 1.0)\",\"showbackground\":true},\"yaxis\":{\"ticks\":\"\",\"linecolor\":\"rgba(255, 255, 255, 1.0)\",\"gridcolor\":\"rgba(255, 255, 255, 1.0)\",\"gridwidth\":2.0,\"zerolinecolor\":\"rgba(255, 255, 255, 1.0)\",\"backgroundcolor\":\"rgba(229, 236, 246, 1.0)\",\"showbackground\":true},\"zaxis\":{\"ticks\":\"\",\"linecolor\":\"rgba(255, 255, 255, 1.0)\",\"gridcolor\":\"rgba(255, 255, 255, 1.0)\",\"gridwidth\":2.0,\"zerolinecolor\":\"rgba(255, 255, 255, 1.0)\",\"backgroundcolor\":\"rgba(229, 236, 246, 1.0)\",\"showbackground\":true}},\"ternary\":{\"aaxis\":{\"ticks\":\"\",\"linecolor\":\"rgba(255, 255, 255, 1.0)\",\"gridcolor\":\"rgba(255, 255, 255, 1.0)\"},\"baxis\":{\"ticks\":\"\",\"linecolor\":\"rgba(255, 255, 255, 1.0)\",\"gridcolor\":\"rgba(255, 255, 255, 1.0)\"},\"caxis\":{\"ticks\":\"\",\"linecolor\":\"rgba(255, 255, 255, 1.0)\",\"gridcolor\":\"rgba(255, 255, 255, 1.0)\"},\"bgcolor\":\"rgba(229, 236, 246, 1.0)\"},\"xaxis\":{\"title\":{\"standoff\":15},\"ticks\":\"\",\"automargin\":\"height+width+left+right+top+bottom\",\"linecolor\":\"rgba(255, 255, 255, 1.0)\",\"gridcolor\":\"rgba(255, 255, 255, 1.0)\",\"zerolinecolor\":\"rgba(255, 255, 255, 1.0)\",\"zerolinewidth\":2.0},\"yaxis\":{\"title\":{\"standoff\":15},\"ticks\":\"\",\"automargin\":\"height+width+left+right+top+bottom\",\"linecolor\":\"rgba(255, 255, 255, 1.0)\",\"gridcolor\":\"rgba(255, 255, 255, 1.0)\",\"zerolinecolor\":\"rgba(255, 255, 255, 1.0)\",\"zerolinewidth\":2.0},\"annotationdefaults\":{\"arrowcolor\":\"#2a3f5f\",\"arrowhead\":0,\"arrowwidth\":1},\"shapedefaults\":{\"line\":{\"color\":\"rgba(42, 63, 95, 1.0)\"}},\"colorway\":[\"rgba(99, 110, 250, 1.0)\",\"rgba(239, 85, 59, 1.0)\",\"rgba(0, 204, 150, 1.0)\",\"rgba(171, 99, 250, 1.0)\",\"rgba(255, 161, 90, 1.0)\",\"rgba(25, 211, 243, 1.0)\",\"rgba(255, 102, 146, 1.0)\",\"rgba(182, 232, 128, 1.0)\",\"rgba(255, 151, 255, 1.0)\",\"rgba(254, 203, 82, 1.0)\"]},\"data\":{\"bar\":[{\"marker\":{\"line\":{\"color\":\"rgba(229, 236, 246, 1.0)\",\"width\":0.5},\"pattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2}},\"error_x\":{\"color\":\"rgba(42, 63, 95, 1.0)\"},\"error_y\":{\"color\":\"rgba(42, 63, 95, 1.0)\"}}],\"barpolar\":[{\"marker\":{\"line\":{\"color\":\"rgba(229, 236, 246, 1.0)\",\"width\":0.5},\"pattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2}}}],\"carpet\":[{\"aaxis\":{\"linecolor\":\"rgba(255, 255, 255, 1.0)\",\"gridcolor\":\"rgba(255, 255, 255, 1.0)\",\"endlinecolor\":\"rgba(42, 63, 95, 1.0)\",\"minorgridcolor\":\"rgba(255, 255, 255, 1.0)\",\"startlinecolor\":\"rgba(42, 63, 95, 1.0)\"},\"baxis\":{\"linecolor\":\"rgba(255, 255, 255, 1.0)\",\"gridcolor\":\"rgba(255, 255, 255, 1.0)\",\"endlinecolor\":\"rgba(42, 63, 95, 1.0)\",\"minorgridcolor\":\"rgba(255, 255, 255, 1.0)\",\"startlinecolor\":\"rgba(42, 63, 95, 1.0)\"}}],\"choropleth\":[{\"colorbar\":{\"outlinewidth\":0.0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"contour\":[{\"colorbar\":{\"outlinewidth\":0.0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"contourcarpet\":[{\"colorbar\":{\"outlinewidth\":0.0,\"ticks\":\"\"}}],\"heatmap\":[{\"colorbar\":{\"outlinewidth\":0.0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"heatmapgl\":[{\"colorbar\":{\"outlinewidth\":0.0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"histogram\":[{\"marker\":{\"pattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2}}}],\"histogram2d\":[{\"colorbar\":{\"outlinewidth\":0.0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"histogram2dcontour\":[{\"colorbar\":{\"outlinewidth\":0.0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"mesh3d\":[{\"colorbar\":{\"outlinewidth\":0.0,\"ticks\":\"\"}}],\"parcoords\":[{\"line\":{\"colorbar\":{\"outlinewidth\":0.0,\"ticks\":\"\"}}}],\"pie\":[{\"automargin\":true}],\"scatter\":[{\"marker\":{\"colorbar\":{\"outlinewidth\":0.0,\"ticks\":\"\"}}}],\"scatter3d\":[{\"marker\":{\"colorbar\":{\"outlinewidth\":0.0,\"ticks\":\"\"}},\"line\":{\"colorbar\":{\"outlinewidth\":0.0,\"ticks\":\"\"}}}],\"scattercarpet\":[{\"marker\":{\"colorbar\":{\"outlinewidth\":0.0,\"ticks\":\"\"}}}],\"scattergeo\":[{\"marker\":{\"colorbar\":{\"outlinewidth\":0.0,\"ticks\":\"\"}}}],\"scattergl\":[{\"marker\":{\"colorbar\":{\"outlinewidth\":0.0,\"ticks\":\"\"}}}],\"scattermapbox\":[{\"marker\":{\"colorbar\":{\"outlinewidth\":0.0,\"ticks\":\"\"}}}],\"scatterpolar\":[{\"marker\":{\"colorbar\":{\"outlinewidth\":0.0,\"ticks\":\"\"}}}],\"scatterpolargl\":[{\"marker\":{\"colorbar\":{\"outlinewidth\":0.0,\"ticks\":\"\"}}}],\"scatterternary\":[{\"marker\":{\"colorbar\":{\"outlinewidth\":0.0,\"ticks\":\"\"}}}],\"surface\":[{\"colorbar\":{\"outlinewidth\":0.0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"table\":[{\"cells\":{\"fill\":{\"color\":\"rgba(235, 240, 248, 1.0)\"},\"line\":{\"color\":\"rgba(255, 255, 255, 1.0)\"}},\"header\":{\"fill\":{\"color\":\"rgba(200, 212, 227, 1.0)\"},\"line\":{\"color\":\"rgba(255, 255, 255, 1.0)\"}}}]}},\"title\":{\"text\":\"Top 10 Languages - Stack Overflow Survey 2025\",\"x\":0.5,\"y\":0.95},\"margin\":{\"l\":140,\"r\":30,\"t\":60,\"b\":50},\"xaxis\":{\"title\":{\"text\":\"% of Respondents\"}},\"yaxis\":{}};\n",
       "        var config = {\"responsive\":false};\n",
       "        Plotly.newPlot('114159d1-610f-4ad9-9b6b-57d18c11facd', data, layout, config);\n",
       "    });\n",
       "};\n",
       "if ((typeof(requirejs) !==  typeof(Function)) || (typeof(requirejs.config) !== typeof(Function))) {\n",
       "    var script = document.createElement(\"script\");\n",
       "    script.setAttribute(\"charset\", \"utf-8\");\n",
       "    script.setAttribute(\"src\", \"https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js\");\n",
       "    script.onload = function(){\n",
       "        renderPlotly_114159d1610f4ad99b6b57d18c11facd();\n",
       "    };\n",
       "    document.getElementsByTagName(\"head\")[0].appendChild(script);\n",
       "}\n",
       "else {\n",
       "    renderPlotly_114159d1610f4ad99b6b57d18c11facd();\n",
       "}\n",
       "</script></div>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "using System.Net.Http;\n",
    "using System.Text.RegularExpressions;\n",
    "using Plotly.NET;\n",
    "using Plotly.NET.Interactive;\n",
    "using Plotly.NET.LayoutObjects;\n",
    "\n",
    "var surveyUrl = \"https://survey.stackoverflow.co/2025\";\n",
    "var topLangs = new List<(string Language, double Percent)>();\n",
    "\n",
    "var targetLanguages = new HashSet<string>(StringComparer.OrdinalIgnoreCase)\n",
    "{\n",
    "    \"JavaScript\", \"HTML/CSS\", \"SQL\", \"Python\", \"Bash/Shell\",\n",
    "    \"TypeScript\", \"Java\", \"C#\", \"C++\", \"PowerShell\"\n",
    "};\n",
    "\n",
    "try\n",
    "{\n",
    "    using var http = new HttpClient();\n",
    "    http.DefaultRequestHeaders.UserAgent.ParseAdd(\"Mozilla/5.0 (compatible; CSCSBook/1.0)\");\n",
    "    var html = await http.GetStringAsync(surveyUrl);\n",
    "\n",
    "    // Parse language entries such as \"JavaScript 66%\" that appear in chart payload/content.\n",
    "    var matches = Regex.Matches(\n",
    "        html,\n",
    "        @\"(JavaScript|HTML/CSS|SQL|Python|Bash/Shell(?:\\s*\\(all shells\\))?|TypeScript|Java|C#|C\\+\\+|PowerShell)\\s*([0-9]+(?:\\.[0-9]+)?)%\",\n",
    "        RegexOptions.IgnoreCase\n",
    "    );\n",
    "\n",
    "    foreach (Match m in matches)\n",
    "    {\n",
    "        var rawLanguage = m.Groups[1].Value.Trim();\n",
    "        var language = rawLanguage.StartsWith(\"Bash/Shell\", StringComparison.OrdinalIgnoreCase) ? \"Bash/Shell\" : rawLanguage;\n",
    "        if (!targetLanguages.Contains(language)) continue;\n",
    "\n",
    "        var pct = double.Parse(m.Groups[2].Value);\n",
    "        if (!topLangs.Any(x => x.Language.Equals(language, StringComparison.OrdinalIgnoreCase)))\n",
    "            topLangs.Add((language, pct));\n",
    "    }\n",
    "}\n",
    "catch\n",
    "{\n",
    "    // Network or parsing failures should not break the notebook build.\n",
    "}\n",
    "\n",
    "if (topLangs.Count < 10)\n",
    "{\n",
    "    // Fallback top-10 values (Stack Overflow Developer Survey 2025, published summary/chart).\n",
    "    topLangs = new List<(string, double)>\n",
    "    {\n",
    "        (\"JavaScript\", 66.0),\n",
    "        (\"HTML/CSS\", 61.9),\n",
    "        (\"SQL\", 58.6),\n",
    "        (\"Python\", 57.9),\n",
    "        (\"Bash/Shell\", 48.7),\n",
    "        (\"TypeScript\", 43.8),\n",
    "        (\"Java\", 29.5),\n",
    "        (\"C#\", 27.9),\n",
    "        (\"C++\", 23.6),\n",
    "        (\"PowerShell\", 23.3),\n",
    "    };\n",
    "}\n",
    "\n",
    "var ordered = topLangs\n",
    "    .OrderByDescending(x => x.Percent)\n",
    "    .Take(10)\n",
    "    .OrderBy(x => x.Percent)\n",
    "    .ToArray();\n",
    "\n",
    "var langs = ordered.Select(x => x.Language).ToArray();\n",
    "var pcts = ordered.Select(x => x.Percent).ToArray();\n",
    "\n",
    "Chart2D.Chart.Bar<double, string, string, string, string>(\n",
    "    values: pcts,\n",
    "    Keys: langs,\n",
    "    Name: \"% Used\"\n",
    " )\n",
    ".WithLayout(Layout.init<string>(\n",
    "    Width: 500, Height: 320,\n",
    "    Title: Title.init(\"Top 10 Languages - Stack Overflow Survey 2025\", X: 0.5, Y: 0.95),\n",
    "    Margin: Margin.init<int, int, int, int, int, int>(Top: 60, Right: 30, Bottom: 50, Left: 140)\n",
    ")).WithXAxis(LinearAxis.init<string, string, string, string, string, string, string, string>(\n",
    "    Title: Title.init(\"% of Respondents\")\n",
    "))\n",
    ".WithYAxis(LinearAxis.init<string, string, string, string, string, string, string, string>(\n",
    "))\n",
    ".WithConfig(Config.init(Responsive: false))\n",
    ".Display();\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6e373ac2",
   "metadata": {},
   "source": [
    "Also, according to [TIOBE Index](https://www.tiobe.com/tiobe-index/), C# is one of the most popular languages according to the number of [search engine hits](https://www.tiobe.com/tiobe-index/programminglanguages_definition/)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "22fb2597",
   "metadata": {
    "language_info": {
     "name": "polyglot-notebook"
    },
    "polyglot_notebook": {
     "kernelName": "csharp"
    },
    "tags": [
     "remove-input",
     "remove-output"
    ]
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><div></div><div></div><div><strong>Installed Packages</strong><ul><li><span>HtmlAgilityPack, 1.12.4</span></li></ul></div></div>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#r \"nuget: HtmlAgilityPack\"\n",
    "// #r \"nuget: Plotly.NET\"\n",
    "// #r \"nuget: Plotly.NET.Interactive\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "50ac2803",
   "metadata": {
    "language_info": {
     "name": "polyglot-notebook"
    },
    "polyglot_notebook": {
     "kernelName": "csharp"
    },
    "tags": [
     "hide-input"
    ]
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><div id=\"1219c940-38ae-4c15-bafc-9951c44073ae\"><!-- Plotly chart will be drawn inside this DIV --></div><script type=\"text/javascript\">\n",
       "var renderPlotly_1219c94038ae4c15bafc9951c44073ae = function() {\n",
       "    var fsharpPlotlyRequire = requirejs.config({context:'fsharp-plotly',paths:{plotly:'https://cdn.plot.ly/plotly-2.27.1.min'}}) || require;\n",
       "    fsharpPlotlyRequire(['plotly'], function(Plotly) {\n",
       "        var data = [{\"type\":\"bar\",\"name\":\"TIOBE Index\",\"x\":[1.8,1.88,2.0,2.5,3.45,6.36,7.99,8.18,11.55,21.25],\"y\":[\"Delphi/Object Pascal\",\"R\",\"SQL\",\"Visual Basic\",\"JavaScript\",\"C#\",\"Java\",\"C++\",\"C\",\"Python\"],\"orientation\":\"h\",\"marker\":{\"pattern\":{}}}];\n",
       "        var layout = {\"width\":500,\"height\":320,\"template\":{\"layout\":{\"title\":{\"x\":0.05},\"font\":{\"color\":\"rgba(42, 63, 95, 1.0)\"},\"paper_bgcolor\":\"rgba(255, 255, 255, 1.0)\",\"plot_bgcolor\":\"rgba(229, 236, 246, 1.0)\",\"autotypenumbers\":\"strict\",\"colorscale\":{\"diverging\":[[0.0,\"#8e0152\"],[0.1,\"#c51b7d\"],[0.2,\"#de77ae\"],[0.3,\"#f1b6da\"],[0.4,\"#fde0ef\"],[0.5,\"#f7f7f7\"],[0.6,\"#e6f5d0\"],[0.7,\"#b8e186\"],[0.8,\"#7fbc41\"],[0.9,\"#4d9221\"],[1.0,\"#276419\"]],\"sequential\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]],\"sequentialminus\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]},\"hovermode\":\"closest\",\"hoverlabel\":{\"align\":\"left\"},\"coloraxis\":{\"colorbar\":{\"outlinewidth\":0.0,\"ticks\":\"\"}},\"geo\":{\"showland\":true,\"landcolor\":\"rgba(229, 236, 246, 1.0)\",\"showlakes\":true,\"lakecolor\":\"rgba(255, 255, 255, 1.0)\",\"subunitcolor\":\"rgba(255, 255, 255, 1.0)\",\"bgcolor\":\"rgba(255, 255, 255, 1.0)\"},\"mapbox\":{\"style\":\"light\"},\"polar\":{\"bgcolor\":\"rgba(229, 236, 246, 1.0)\",\"radialaxis\":{\"linecolor\":\"rgba(255, 255, 255, 1.0)\",\"gridcolor\":\"rgba(255, 255, 255, 1.0)\",\"ticks\":\"\"},\"angularaxis\":{\"linecolor\":\"rgba(255, 255, 255, 1.0)\",\"gridcolor\":\"rgba(255, 255, 255, 1.0)\",\"ticks\":\"\"}},\"scene\":{\"xaxis\":{\"ticks\":\"\",\"linecolor\":\"rgba(255, 255, 255, 1.0)\",\"gridcolor\":\"rgba(255, 255, 255, 1.0)\",\"gridwidth\":2.0,\"zerolinecolor\":\"rgba(255, 255, 255, 1.0)\",\"backgroundcolor\":\"rgba(229, 236, 246, 1.0)\",\"showbackground\":true},\"yaxis\":{\"ticks\":\"\",\"linecolor\":\"rgba(255, 255, 255, 1.0)\",\"gridcolor\":\"rgba(255, 255, 255, 1.0)\",\"gridwidth\":2.0,\"zerolinecolor\":\"rgba(255, 255, 255, 1.0)\",\"backgroundcolor\":\"rgba(229, 236, 246, 1.0)\",\"showbackground\":true},\"zaxis\":{\"ticks\":\"\",\"linecolor\":\"rgba(255, 255, 255, 1.0)\",\"gridcolor\":\"rgba(255, 255, 255, 1.0)\",\"gridwidth\":2.0,\"zerolinecolor\":\"rgba(255, 255, 255, 1.0)\",\"backgroundcolor\":\"rgba(229, 236, 246, 1.0)\",\"showbackground\":true}},\"ternary\":{\"aaxis\":{\"ticks\":\"\",\"linecolor\":\"rgba(255, 255, 255, 1.0)\",\"gridcolor\":\"rgba(255, 255, 255, 1.0)\"},\"baxis\":{\"ticks\":\"\",\"linecolor\":\"rgba(255, 255, 255, 1.0)\",\"gridcolor\":\"rgba(255, 255, 255, 1.0)\"},\"caxis\":{\"ticks\":\"\",\"linecolor\":\"rgba(255, 255, 255, 1.0)\",\"gridcolor\":\"rgba(255, 255, 255, 1.0)\"},\"bgcolor\":\"rgba(229, 236, 246, 1.0)\"},\"xaxis\":{\"title\":{\"standoff\":15},\"ticks\":\"\",\"automargin\":\"height+width+left+right+top+bottom\",\"linecolor\":\"rgba(255, 255, 255, 1.0)\",\"gridcolor\":\"rgba(255, 255, 255, 1.0)\",\"zerolinecolor\":\"rgba(255, 255, 255, 1.0)\",\"zerolinewidth\":2.0},\"yaxis\":{\"title\":{\"standoff\":15},\"ticks\":\"\",\"automargin\":\"height+width+left+right+top+bottom\",\"linecolor\":\"rgba(255, 255, 255, 1.0)\",\"gridcolor\":\"rgba(255, 255, 255, 1.0)\",\"zerolinecolor\":\"rgba(255, 255, 255, 1.0)\",\"zerolinewidth\":2.0},\"annotationdefaults\":{\"arrowcolor\":\"#2a3f5f\",\"arrowhead\":0,\"arrowwidth\":1},\"shapedefaults\":{\"line\":{\"color\":\"rgba(42, 63, 95, 1.0)\"}},\"colorway\":[\"rgba(99, 110, 250, 1.0)\",\"rgba(239, 85, 59, 1.0)\",\"rgba(0, 204, 150, 1.0)\",\"rgba(171, 99, 250, 1.0)\",\"rgba(255, 161, 90, 1.0)\",\"rgba(25, 211, 243, 1.0)\",\"rgba(255, 102, 146, 1.0)\",\"rgba(182, 232, 128, 1.0)\",\"rgba(255, 151, 255, 1.0)\",\"rgba(254, 203, 82, 1.0)\"]},\"data\":{\"bar\":[{\"marker\":{\"line\":{\"color\":\"rgba(229, 236, 246, 1.0)\",\"width\":0.5},\"pattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2}},\"error_x\":{\"color\":\"rgba(42, 63, 95, 1.0)\"},\"error_y\":{\"color\":\"rgba(42, 63, 95, 1.0)\"}}],\"barpolar\":[{\"marker\":{\"line\":{\"color\":\"rgba(229, 236, 246, 1.0)\",\"width\":0.5},\"pattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2}}}],\"carpet\":[{\"aaxis\":{\"linecolor\":\"rgba(255, 255, 255, 1.0)\",\"gridcolor\":\"rgba(255, 255, 255, 1.0)\",\"endlinecolor\":\"rgba(42, 63, 95, 1.0)\",\"minorgridcolor\":\"rgba(255, 255, 255, 1.0)\",\"startlinecolor\":\"rgba(42, 63, 95, 1.0)\"},\"baxis\":{\"linecolor\":\"rgba(255, 255, 255, 1.0)\",\"gridcolor\":\"rgba(255, 255, 255, 1.0)\",\"endlinecolor\":\"rgba(42, 63, 95, 1.0)\",\"minorgridcolor\":\"rgba(255, 255, 255, 1.0)\",\"startlinecolor\":\"rgba(42, 63, 95, 1.0)\"}}],\"choropleth\":[{\"colorbar\":{\"outlinewidth\":0.0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"contour\":[{\"colorbar\":{\"outlinewidth\":0.0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"contourcarpet\":[{\"colorbar\":{\"outlinewidth\":0.0,\"ticks\":\"\"}}],\"heatmap\":[{\"colorbar\":{\"outlinewidth\":0.0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"heatmapgl\":[{\"colorbar\":{\"outlinewidth\":0.0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"histogram\":[{\"marker\":{\"pattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2}}}],\"histogram2d\":[{\"colorbar\":{\"outlinewidth\":0.0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"histogram2dcontour\":[{\"colorbar\":{\"outlinewidth\":0.0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"mesh3d\":[{\"colorbar\":{\"outlinewidth\":0.0,\"ticks\":\"\"}}],\"parcoords\":[{\"line\":{\"colorbar\":{\"outlinewidth\":0.0,\"ticks\":\"\"}}}],\"pie\":[{\"automargin\":true}],\"scatter\":[{\"marker\":{\"colorbar\":{\"outlinewidth\":0.0,\"ticks\":\"\"}}}],\"scatter3d\":[{\"marker\":{\"colorbar\":{\"outlinewidth\":0.0,\"ticks\":\"\"}},\"line\":{\"colorbar\":{\"outlinewidth\":0.0,\"ticks\":\"\"}}}],\"scattercarpet\":[{\"marker\":{\"colorbar\":{\"outlinewidth\":0.0,\"ticks\":\"\"}}}],\"scattergeo\":[{\"marker\":{\"colorbar\":{\"outlinewidth\":0.0,\"ticks\":\"\"}}}],\"scattergl\":[{\"marker\":{\"colorbar\":{\"outlinewidth\":0.0,\"ticks\":\"\"}}}],\"scattermapbox\":[{\"marker\":{\"colorbar\":{\"outlinewidth\":0.0,\"ticks\":\"\"}}}],\"scatterpolar\":[{\"marker\":{\"colorbar\":{\"outlinewidth\":0.0,\"ticks\":\"\"}}}],\"scatterpolargl\":[{\"marker\":{\"colorbar\":{\"outlinewidth\":0.0,\"ticks\":\"\"}}}],\"scatterternary\":[{\"marker\":{\"colorbar\":{\"outlinewidth\":0.0,\"ticks\":\"\"}}}],\"surface\":[{\"colorbar\":{\"outlinewidth\":0.0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"table\":[{\"cells\":{\"fill\":{\"color\":\"rgba(235, 240, 248, 1.0)\"},\"line\":{\"color\":\"rgba(255, 255, 255, 1.0)\"}},\"header\":{\"fill\":{\"color\":\"rgba(200, 212, 227, 1.0)\"},\"line\":{\"color\":\"rgba(255, 255, 255, 1.0)\"}}}]}},\"title\":{\"text\":\"TIOBE Programming Community Index\",\"x\":0.5,\"y\":0.95},\"margin\":{\"l\":120,\"r\":20,\"t\":60,\"b\":50},\"xaxis\":{\"title\":{\"text\":\"Rating (%)\"}},\"yaxis\":{}};\n",
       "        var config = {\"responsive\":false};\n",
       "        Plotly.newPlot('1219c940-38ae-4c15-bafc-9951c44073ae', data, layout, config);\n",
       "    });\n",
       "};\n",
       "if ((typeof(requirejs) !==  typeof(Function)) || (typeof(requirejs.config) !== typeof(Function))) {\n",
       "    var script = document.createElement(\"script\");\n",
       "    script.setAttribute(\"charset\", \"utf-8\");\n",
       "    script.setAttribute(\"src\", \"https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js\");\n",
       "    script.onload = function(){\n",
       "        renderPlotly_1219c94038ae4c15bafc9951c44073ae();\n",
       "    };\n",
       "    document.getElementsByTagName(\"head\")[0].appendChild(script);\n",
       "}\n",
       "else {\n",
       "    renderPlotly_1219c94038ae4c15bafc9951c44073ae();\n",
       "}\n",
       "</script></div>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "using System.Reflection;\n",
    "using System.Runtime.CompilerServices;\n",
    "using HtmlAgilityPack;\n",
    "using Plotly.NET;\n",
    "using Plotly.NET.Interactive;\n",
    "using Plotly.NET.LayoutObjects;\n",
    "\n",
    "var web = new HtmlWeb();\n",
    "var doc = web.Load(\"https://www.tiobe.com/tiobe-index/\");\n",
    "\n",
    "var rows = doc.DocumentNode.SelectNodes(\"//table[contains(@class,'table-top20')]//tr\");\n",
    "\n",
    "var languages = new List<string>();\n",
    "var ratings = new List<double>();\n",
    "\n",
    "foreach (var row in rows.Skip(1))\n",
    "{\n",
    "    var cells = row.SelectNodes(\"td\");\n",
    "    if (cells != null && cells.Count >= 6)\n",
    "    {\n",
    "        languages.Add(cells[4].InnerText.Trim());\n",
    "        if (double.TryParse(cells[5].InnerText.Replace(\"%\", \"\").Trim(), out double rating))\n",
    "            ratings.Add(rating);\n",
    "    }\n",
    "}\n",
    "\n",
    "var top10Languages = languages.Take(10).Reverse().ToArray();\n",
    "var top10Ratings = ratings.Take(10).Reverse().ToArray();\n",
    "\n",
    "var chart = Chart2D.Chart.Bar<double, string, string, string, string>(\n",
    "    values: top10Ratings,\n",
    "    Keys: top10Languages,\n",
    "    Name: \"TIOBE Index\"\n",
    ")\n",
    ".WithTitle(\"TIOBE Programming Community Index\")\n",
    ".WithLayout(Layout.init<string>(\n",
    "    Width: 500,\n",
    "    Height: 320,\n",
    "    Title: Title.init(\"TIOBE Programming Community Index\", X: 0.5, Y: 0.95),\n",
    "    Margin: Margin.init<int, int, int, int, int, int>(Top: 60, Right: 20, Bottom: 50, Left: 120)\n",
    ")).WithXAxis(LinearAxis.init<string, string, string, string, string, string, string, string>(\n",
    "    Title: Title.init(\"Rating (%)\")\n",
    "))\n",
    ".WithYAxis(LinearAxis.init<string, string, string, string, string, string, string, string>(\n",
    "))\n",
    ".WithConfig(Config.init(Responsive: false));\n",
    "// chart.Show();\n",
    "chart.Display();"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8b241038",
   "metadata": {},
   "source": [
    "```{rubric} Footnotes\n",
    "```\n",
    "\n",
    "[^1]: Andrew N. Harrington & George Thiruvathukal. (2021). Introduction to Computer Science in C#. <https://introcs.cs.luc.edu>\n",
    "\n",
    "[^stack-overflow-survey]: Stack Overflow (2025). Stack Overflow Annual Developer Survey. https://survey.stackoverflow.co/"
   ]
  }
 ],
 "metadata": {
  "jupytext": {
   "cell_metadata_filter": "-all",
   "main_language": "python",
   "notebook_metadata_filter": "-all"
  },
  "kernelspec": {
   "display_name": ".NET (C#)",
   "language": "C#",
   "name": ".net-csharp"
  },
  "language_info": {
   "name": "polyglot-notebook"
  },
  "polyglot_notebook": {
   "kernelInfo": {
    "defaultKernelName": "csharp",
    "items": [
     {
      "aliases": [],
      "name": "csharp"
     }
    ]
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
