{
  "version": "https://jsonfeed.org/version/1.1",
  "title": "Lazy_V's Blog",
  "home_page_url": "https://zzxzzk115.github.io/blog/",
  "feed_url": "https://zzxzzk115.github.io/blog/feed.json",
  "description": "Notes on graphics, games, and things I build. By Kexuan Zhang / Lazy_V.",
  "items": [
    {
      "title": "Repeated macOS Permission Prompts with GodotSteam or a Custom Godot Build",
      "url": "https://zzxzzk115.github.io/blog/posts/game-engine/godotsteam-macos-permission.html",
      "id": "https://zzxzzk115.github.io/blog/posts/game-engine/godotsteam-macos-permission.html",
      "summary": "These are the steps I used for repeated permission prompts with a locally installed GodotSteam build on macOS. First, reset the relevant privacy permissions. Use the bundle iden...",
      "content_html": "<p>These are the steps I used for repeated permission prompts with a locally installed GodotSteam build on macOS.</p>\n<p>First, reset the relevant privacy permissions. Use the bundle identifier of your build; the command below uses Godot's identifier:</p>\n<div class=\"language-bash line-numbers-mode\" data-highlighter=\"shiki\" data-ext=\"bash\" style=\"--shiki-light:#383A42;--shiki-dark:#abb2bf;--shiki-light-bg:#FAFAFA;--shiki-dark-bg:#282c34\"><pre class=\"shiki shiki-themes one-light one-dark-pro vp-code\"><code class=\"language-bash\"><span class=\"line\"><span style=\"--shiki-light:#4078F2;--shiki-dark:#61AFEF\">tccutil</span><span style=\"--shiki-light:#50A14F;--shiki-dark:#98C379\"> reset</span><span style=\"--shiki-light:#50A14F;--shiki-dark:#98C379\"> All</span><span style=\"--shiki-light:#50A14F;--shiki-dark:#98C379\"> org.godotengine.godot</span></span></code></pre>\n<div class=\"line-numbers\" aria-hidden=\"true\" style=\"counter-reset:line-number 0\"><div class=\"line-number\"></div></div></div><p>Then open <strong>System Settings → Privacy &amp; Security → Full Disk Access</strong>, click <strong>+</strong>, and add GodotSteam (or your custom Godot build).</p>\n<p>Finally, apply an ad-hoc signature to the app bundle. Replace the path with the location of your app; mine is in <code>/Applications</code>:</p>\n<div class=\"language-bash line-numbers-mode\" data-highlighter=\"shiki\" data-ext=\"bash\" style=\"--shiki-light:#383A42;--shiki-dark:#abb2bf;--shiki-light-bg:#FAFAFA;--shiki-dark-bg:#282c34\"><pre class=\"shiki shiki-themes one-light one-dark-pro vp-code\"><code class=\"language-bash\"><span class=\"line\"><span style=\"--shiki-light:#4078F2;--shiki-dark:#61AFEF\">codesign</span><span style=\"--shiki-light:#986801;--shiki-dark:#D19A66\"> --force</span><span style=\"--shiki-light:#986801;--shiki-dark:#D19A66\"> --deep</span><span style=\"--shiki-light:#986801;--shiki-dark:#D19A66\"> --sign</span><span style=\"--shiki-light:#50A14F;--shiki-dark:#98C379\"> -</span><span style=\"--shiki-light:#50A14F;--shiki-dark:#98C379\"> /Applications/GodotSteam.app</span></span></code></pre>\n<div class=\"line-numbers\" aria-hidden=\"true\" style=\"counter-reset:line-number 0\"><div class=\"line-number\"></div></div></div>",
      "date_published": "2026-04-12T00:00:00.000Z",
      "date_modified": "2026-10-17T16:08:05.000Z",
      "authors": [
        {
          "name": "Lazy_V"
        }
      ],
      "tags": [
        "Game Engines"
      ]
    },
    {
      "title": "IEEE TVCG Submission Guidelines",
      "url": "https://zzxzzk115.github.io/blog/posts/phd-life/ieee-tvcg-guidelines.html",
      "id": "https://zzxzzk115.github.io/blog/posts/phd-life/ieee-tvcg-guidelines.html",
      "summary": "A general checklist to read before preparing a submission.",
      "content_html": "<p>A checklist to read before preparing a submission.</p>\n<!-- more -->\n<h1>IEEE TVCG Submission Guidelines — General Summary</h1>\n<blockquote>\n<p>This is an AI-generated summary of general IEEE Computer Society journal submission procedures, with a focus on IEEE Transactions on Visualization and Computer Graphics (TVCG), based on the <a href=\"https://www.computer.org/publications/author-resources#pubs\" target=\"_blank\" rel=\"noopener noreferrer\">author resources</a>.</p>\n<p>It is a personal reference, not the journal's official instructions. Figures and procedural details quoted below come from the original March 2026 summary and have not been independently verified for every TVCG article type. Check the journal's current instructions for page limits, fees, abstract length, file requirements, and the submission system before submitting.</p>\n</blockquote>\n<h2>1. Choosing a publication</h2>\n<p>IEEE Computer Society publishes journals and magazines:</p>\n<ul>\n<li><strong>Journals / Transactions:</strong> peer-reviewed publications for complete research results, such as TVCG, TPAMI, and TSE.</li>\n<li><strong>Magazines:</strong> publications with a stronger emphasis on overviews, applications, and trends; review procedures depend on the publication.</li>\n</ul>\n<h3>TVCG's focus</h3>\n<p>TVCG covers computer graphics, visualisation, and VR/AR. Important aspects of a submission include technical completeness, thorough experimental validation, and reproducibility. The original summary cited an acceptance rate of approximately 25%; treat that as an unverified contextual figure, not a current official statistic.</p>\n<h2>2. Preparing the manuscript</h2>\n<h3>File formats</h3>\n<p>The original summary lists LaTeX, Microsoft Word, and plain text among general IEEE preparation formats. Use the journal's official templates and confirm which submission files its current portal accepts. The IEEE LaTeX Analyzer can be useful for checking a LaTeX manuscript.</p>\n<h3>Abstract</h3>\n<p>The original summary gives a general journal abstract length of 100–200 words. Confirm the requirement for your article type. A useful abstract states:</p>\n<ul>\n<li>The research problem</li>\n<li>The approach</li>\n<li>The main results</li>\n<li>Their significance</li>\n</ul>\n<p>Keep the abstract self-contained, without references or mathematical notation that requires explanation elsewhere.</p>\n<h3>Page limits</h3>\n<p>The original summary quotes a standard length of <strong>12 formatted pages</strong>, including the abstract and references, and an excess-page charge of <strong>USD 220 per page</strong>. These figures must be checked against the current TVCG instructions and your article type; they are not a quotation of a verified current fee schedule.</p>\n<p>It also suggests submitting appendices as supplemental material. Confirm the journal's current rules before separating material essential to understanding or evaluating the work.</p>\n<h3>Figures and tables</h3>\n<p>Prepare figures at an appropriate resolution; the original checklist gives 300 dpi as a general reference. Place them near the relevant discussion, make labels and legends legible, and follow the publisher's requirements for final figure files.</p>\n<p>The original checklist suggests filenames such as <code>lastname-fig1</code> and <code>lastname-fig2a</code>. A good figure should communicate a method or result clearly without overcrowding the image.</p>\n<h3>References</h3>\n<p>Use IEEE reference formatting, numbered in citation order. A schematic entry is:</p>\n<div class=\"language-text line-numbers-mode\" data-highlighter=\"shiki\" data-ext=\"text\" style=\"--shiki-light:#383A42;--shiki-dark:#abb2bf;--shiki-light-bg:#FAFAFA;--shiki-dark-bg:#282c34\"><pre class=\"shiki shiki-themes one-light one-dark-pro vp-code\"><code class=\"language-text\"><span class=\"line\"><span>[1] Author(s), Title, Journal/Conference, Year, pages.</span></span></code></pre>\n<div class=\"line-numbers\" aria-hidden=\"true\" style=\"counter-reset:line-number 0\"><div class=\"line-number\"></div></div></div><p>Supply the bibliographic information appropriate to the source: authors, full title, venue, year, volume and issue where applicable, and page range or article number.</p>\n<h3>Writing style</h3>\n<p>Consult the IEEE Editorial Style Manual. Prefer clear sentences and active voice where appropriate, avoid repetition, and define abbreviations on first use.</p>\n<p>A common research-paper structure is:</p>\n<ol>\n<li>Introduction</li>\n<li>Related Work</li>\n<li>Method</li>\n<li>Results</li>\n<li>Discussion / Conclusion</li>\n</ol>\n<h2>3. Supplemental material</h2>\n<p>Useful supplements can include videos, animations, additional figures and tables, code, and extended experiments.</p>\n<p>Upload them as separate files when requested by the portal. The original summary quotes a 350 MB limit; check the current upload limits rather than assuming that value applies to every submission. Follow the journal's rules for appendices and ensure the main paper remains understandable on its own.</p>\n<h2>4. Sharing data and code</h2>\n<p>The original checklist highlights IEEE DataPort for data, and Code Ocean or GitHub for code. Well-documented data and code can support reproducibility and make the work easier to use and evaluate. Choose a suitable repository, licence, and release format for the material you can share.</p>\n<h2>5. Originality and related work</h2>\n<h3>Original work</h3>\n<p>A submission must follow the journal's policies on originality and simultaneous submission. Disclose relevant previously published work rather than presenting it as new.</p>\n<h3>Extending a conference paper</h3>\n<p>Where a journal extension is allowed:</p>\n<ul>\n<li>Cite the original paper.</li>\n<li>Explain the additional contributions.</li>\n<li>Provide the earlier paper when requested.</li>\n</ul>\n<p>Editors and reviewers assess whether the extension contains sufficient new material.</p>\n<h3>Duplicate submission</h3>\n<p>Do not submit the same manuscript to multiple publications at the same time. Undisclosed overlap with published work can also lead to rejection.</p>\n<h2>6. Submitting the paper</h2>\n<p>Follow the submission link on the journal's official website. The original summary mentions ScholarOne and IEEE Author Portal; the current journal page determines which system to use.</p>\n<p>The usual steps are:</p>\n<ol>\n<li>Create or sign in to an account and provide an ORCID when required.</li>\n<li>Enter author information.</li>\n<li>Upload the manuscript and supporting files.</li>\n<li>Select keywords.</li>\n<li>Review the submission and submit it.</li>\n</ol>\n<h3>Keywords</h3>\n<p>Keywords help route the manuscript to appropriate editors and reviewers. The original summary recommends at least three terms from an ACM taxonomy; use the classification and number requested by the actual portal.</p>\n<h3>Suggested or excluded reviewers</h3>\n<p>If the portal allows it, suggest reviewers without conflicts of interest. Requests to exclude reviewers should include an appropriate reason and follow the journal's policy.</p>\n<h2>7. Peer review</h2>\n<p>The original summary describes single-anonymous review, in which reviewers know the authors' identities but authors do not know the reviewers'. Review models differ between journals and submission tracks; do not assume a double-anonymous option exists without checking.</p>\n<p>A typical workflow is:</p>\n<ol>\n<li>Editorial screening</li>\n<li>Assignment to an associate editor</li>\n<li>Reviewer invitations</li>\n<li>Reviews</li>\n<li>Editorial decision</li>\n</ol>\n<p>The original checklist describes three or more reviewers and two to four months per round as general expectations, not guarantees for an individual manuscript.</p>\n<p>Possible outcomes include acceptance, minor revision, major revision, and rejection.</p>\n<h2>8. Ethics and permissions</h2>\n<p>Attribute all sources, obtain any required permissions for reused images or other material, and make sure every author agrees to the submission. Follow IEEE's policies on plagiarism and publication ethics.</p>\n<p>For research involving human participants or animals, provide the applicable ethics approval and explain it in the manuscript as required by the journal and your institution.</p>\n<h2>9. Fees and open access</h2>\n<p>Distinguish traditional publication from open access. Open access may involve an article processing charge; excess-page charges or other fees may be separate. Traditional publication does not necessarily mean that every possible charge is waived.</p>\n<p>The original summary quotes USD 220 per excess page. Check the current journal fee schedule, applicable article type, and any institutional agreement before relying on that figure.</p>\n<h2>10. After acceptance</h2>\n<h3>Final materials</h3>\n<p>The requested package may include:</p>\n<ul>\n<li>LaTeX or Word source files</li>\n<li>Figure files</li>\n<li>Supplemental material</li>\n<li>Copyright or licence forms</li>\n</ul>\n<h3>Early Access</h3>\n<p>Early Access can make an accepted article available and citable before assignment to a regular issue. Follow the publisher's instructions for proofs and corrections; do not assume that a posted article can simply be replaced.</p>\n<h3>Final publication</h3>\n<p>Complete the publisher's production and proof stages, then check the published version and its metadata.</p>\n<h2>11. Practical submission checklist</h2>\n<h3>Technical content</h3>\n<ul>\n<li>Explain the complete pipeline.</li>\n<li>Include suitable quantitative and qualitative evaluation.</li>\n<li>Compare with relevant state-of-the-art methods.</li>\n</ul>\n<h3>Presentation</h3>\n<ul>\n<li>Make the abstract clear.</li>\n<li>State the contributions precisely.</li>\n<li>Use figures that explain the work.</li>\n</ul>\n<p>Common weaknesses include insufficient evaluation, confusing figures, unclear contributions, and incomplete coverage of related work.</p>\n<h2>12. Main points</h2>\n<p>The checklist centres on originality, technical completeness, convincing evaluation, clear writing, and compliance with the journal's format and submission requirements. Acceptance depends on the research itself, the evidence supporting it, and how clearly the manuscript communicates those contributions.</p>\n",
      "date_published": "2026-03-30T00:00:00.000Z",
      "date_modified": "2026-10-17T16:08:05.000Z",
      "authors": [
        {
          "name": "Lazy_V"
        }
      ],
      "tags": [
        "PhD-Life"
      ]
    },
    {
      "title": "Develop OpenXR native PC apps without a headset by using Meta XR Simulator",
      "url": "https://zzxzzk115.github.io/blog/posts/phd-life/openxr-simulator.html",
      "id": "https://zzxzzk115.github.io/blog/posts/phd-life/openxr-simulator.html",
      "summary": "If you don't have an XR headset but you want to develop OpenXR apps, you can use Meta XR Simulator! It's great.",
      "content_html": "<p>If you don't have an XR headset but you want to develop OpenXR apps, you can use Meta XR Simulator! It's great.</p>\n<!-- more -->\n<h2>Download Meta XR Simulator</h2>\n<figure><img src=\"https://zzxzzk115.github.io/blog/images/posts/phd-life/openxr-simulator/download_meta_xr_simulator.png\" alt=\"Download Meta XR Simulator\" tabindex=\"0\" loading=\"lazy\"><figcaption>Download Meta XR Simulator</figcaption></figure>\n<p>Download it from <a href=\"https://developers.meta.com/horizon/downloads/package/meta-xr-simulator\" target=\"_blank\" rel=\"noopener noreferrer\">here</a></p>\n<p>You will get a compressed file, and you have to extract it and get the necessary files.</p>\n<p>We only need the <code>MetaXRSimulator</code> folder. Copy it to somewhere on your machine, for example, <code>C:\\MetaXRSimulator</code>.</p>\n<h2>Configure Currently Active OpenXR Runtime &amp; Run</h2>\n<p>There are two options to configure the currently active OpenXR runtime on Windows:</p>\n<ul>\n<li>Windows Registry</li>\n<li>Environment Variable</li>\n</ul>\n<p>I recommend you to use an temporary environment variable (<code>XR_RUNTIME_JSON</code>) in the IDE or the terminal to set the currently active OpenXR runtime, which will not replace the system default OpenXR runtime.</p>\n\n<p>After configuring the environment variable, just run your OpenXR apps in the same terminal!</p>\n<p>Have fun!</p>\n",
      "image": "https://zzxzzk115.github.io/blog/images/posts/phd-life/openxr-simulator/download_meta_xr_simulator.png",
      "date_published": "2025-02-11T00:00:00.000Z",
      "date_modified": "2025-02-12T00:09:03.000Z",
      "authors": [
        {
          "name": "Lazy_V"
        }
      ],
      "tags": [
        "PhD-Life"
      ]
    },
    {
      "title": "Drawing a Simple Sprite with GBDK",
      "url": "https://zzxzzk115.github.io/blog/game-dev/retro/gameboy/gbdk/003-gbdk-simple-sprites.html",
      "id": "https://zzxzzk115.github.io/blog/game-dev/retro/gameboy/gbdk/003-gbdk-simple-sprites.html",
      "summary": "The Game Boy has a screen resolution of 160 × 144 pixels. That may seem tiny today, but it was enough to bring many memorable characters to life. A sprite is a bitmap image used...",
      "content_html": "<p>The Game Boy has a screen resolution of 160 × 144 pixels. That may seem tiny today, but it was enough to bring many memorable characters to life.</p>\n<p>A <a href=\"https://en.wikipedia.org/wiki/Sprite_(computer_graphics)\" target=\"_blank\" rel=\"noopener noreferrer\">sprite</a> is a bitmap image used to represent a character or other object in a 2D game. Mario's character graphics are a familiar example.</p>\n<p>How can we use GBDK to display a sprite on the Game Boy screen?</p>\n<!-- more -->\n<p>We will draw the graphics in a tile editor, export them as a C array, and load that array into the Game Boy's video memory. In this tutorial, we will use GBTD.</p>\n<div class=\"hint-container info\">\n<p class=\"hint-container-title\">Writing your own tool</p>\n<p>You can also write an exporter yourself, as long as its C array uses the tile-data format expected by GBDK.</p>\n</div>\n<h2>Introducing GBTD</h2>\n<p>Game Boy backgrounds are commonly built from tile maps, and sprite graphics also use small tiles.</p>\n<p>GBTD, the Game Boy Tile Designer, lets us draw tiles and export them as GBDK-compatible C arrays. Here is its interface:</p>\n<figure><img src=\"https://zzxzzk115.github.io/blog/images/game-dev/retro/gameboy/gbdk/gbtd_interface_01.png\" alt=\"GBTD interface\" tabindex=\"0\" loading=\"lazy\"><figcaption>GBTD interface</figcaption></figure>\n<div class=\"hint-container tip\">\n<p class=\"hint-container-title\">GBTD and GBMB on macOS or Linux</p>\n<p>If you have not set up the tools yet, follow the <a href=\"https://zzxzzk115.github.io/blog/game-dev/retro/gameboy/gbdk/002-gbdk-preparation.html\" target=\"_blank\">previous tutorial</a>.</p>\n<p>With the aliases configured, you can launch them directly:</p>\n<div class=\"language-bash line-numbers-mode\" data-highlighter=\"shiki\" data-ext=\"bash\" style=\"--shiki-light:#383A42;--shiki-dark:#abb2bf;--shiki-light-bg:#FAFAFA;--shiki-dark-bg:#282c34\"><pre class=\"shiki shiki-themes one-light one-dark-pro vp-code\"><code class=\"language-bash\"><span class=\"line\"><span style=\"--shiki-light:#A0A1A7;--shiki-light-font-style:italic;--shiki-dark:#7F848E;--shiki-dark-font-style:italic\"># Open GBTD</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#4078F2;--shiki-dark:#61AFEF\">gbtd</span></span>\n<span class=\"line\"></span>\n<span class=\"line\"><span style=\"--shiki-light:#A0A1A7;--shiki-light-font-style:italic;--shiki-dark:#7F848E;--shiki-dark-font-style:italic\"># Open GBMB</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#4078F2;--shiki-dark:#61AFEF\">gbmb</span></span></code></pre>\n<div class=\"line-numbers\" aria-hidden=\"true\" style=\"counter-reset:line-number 0\"><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div></div></div></div>\n<h2>Draw the first sprite</h2>\n<p>We will draw an 8 × 8 smiley face and place it near the centre of the screen.</p>\n<div class=\"hint-container info\">\n<p class=\"hint-container-title\">Why 8 × 8?</p>\n<p>The Game Boy supports two hardware sprite sizes, selected globally:</p>\n<ul>\n<li>8 × 8 pixels</li>\n<li>8 × 16 pixels</li>\n</ul>\n<p>Each tile is 8 × 8 pixels. A smaller visible shape still occupies a complete tile, with the unused pixels transparent. Larger characters can be assembled from multiple hardware sprites. For this example, one 8 × 8 tile is enough.</p>\n</div>\n<p>At the bottom of GBTD is a colour selector. The <strong>L</strong> and <strong>R</strong> indicators show the colour indices assigned to the left and right mouse buttons.</p>\n<p>The four swatches on the right represent indices 0 to 3. A palette determines the actual colours; the default palette displays four shades from white to black.</p>\n<figure><img src=\"https://zzxzzk115.github.io/blog/images/game-dev/retro/gameboy/gbdk/gbtd_color_picker.png\" alt=\"GBTD colour selector\" tabindex=\"0\" loading=\"lazy\"><figcaption>GBTD colour selector</figcaption></figure>\n<p>The left toolbar starts with the pencil and fill tools. Below them are four movement tools, followed by vertical flip, horizontal flip, rotation, and automatic updating.</p>\n<figure><img src=\"https://zzxzzk115.github.io/blog/images/game-dev/retro/gameboy/gbdk/gbtd_left_toolbar.png\" alt=\"GBTD left toolbar\" tabindex=\"0\" loading=\"lazy\"><figcaption>GBTD left toolbar</figcaption></figure>\n<div class=\"hint-container info\">\n<p class=\"hint-container-title\">There is no separate eraser</p>\n<p>GBTD edits indexed colours rather than RGBA pixels. To replace a pixel, paint it with another colour index. For Game Boy sprites, index 0 is transparent when displayed as a sprite.</p>\n</div>\n<p>Click a swatch with the left mouse button to assign that index to the left drawing button; do the same with the right mouse button for the right drawing button. This lets you draw with two indices without repeatedly changing the selection.</p>\n<p>Select the pencil tool, assign the black swatch at index 3 to the left button, and draw a smiley face. You can use your own design as long as it fits inside 8 × 8 pixels.</p>\n<p>Then select the fill tool, choose the light-grey swatch at index 1, and fill the face. Mine looks roughly like this:</p>\n<figure><img src=\"https://zzxzzk115.github.io/blog/images/game-dev/retro/gameboy/gbdk/first_sprite_smile_face.png\" alt=\"The first sprite: a smiley face\" tabindex=\"0\" loading=\"lazy\"><figcaption>The first sprite: a smiley face</figcaption></figure>\n<p>Before exporting, save your work. GBTD stores the editable source in a <code>.gbr</code> file, which you can reopen later.</p>\n<h2>Export the sprite</h2>\n<p>Choose <strong>Files → ExportTo</strong> from the menu and use these settings:</p>\n<figure><img src=\"https://zzxzzk115.github.io/blog/images/game-dev/retro/gameboy/gbdk/export_smile_face_as_gbdk_c_array.png\" alt=\"Exporting the smiley face as a GBDK C array\" tabindex=\"0\" loading=\"lazy\"><figcaption>Exporting the smiley face as a GBDK C array</figcaption></figure>\n<div class=\"hint-container info\">\n<p class=\"hint-container-title\">Important settings</p>\n<ul>\n<li><strong>Filename:</strong> <code>Smile.c</code>, the output filename.</li>\n<li><strong>Type:</strong> <code>GBDK C file</code>, which exports a compatible C array.</li>\n<li><strong>Label:</strong> <code>Smile</code>, the array name we will use in our program.</li>\n<li><strong>Format:</strong> <code>Gameboy 4 color</code>.</li>\n</ul>\n</div>\n<p>Click <strong>OK</strong>. GBTD creates <code>Smile.h</code> and <code>Smile.c</code> alongside the <code>.gbr</code> file. The header contains declarations; the C source contains the actual sprite data. We can now use that array in our program.</p>\n<h2>Write the program</h2>\n<h3>Set up Visual Studio Code and a Makefile</h3>\n<div class=\"hint-container info\">\n<p class=\"hint-container-title\">Info</p>\n<p>The Hello World program was a single file, so it did not need much project configuration. From this point on, we will use Visual Studio Code and a Makefile to organise the examples.</p>\n</div>\n<p>Create a <code>gb-dev</code> directory, then a <code>first-sprite</code> directory inside it. Open <code>gb-dev</code> in Visual Studio Code.</p>\n<p>To configure header lookup and IntelliSense, create <code>.vscode/c_cpp_properties.json</code> inside <code>gb-dev</code>:</p>\n<div class=\"language-json line-numbers-mode\" data-highlighter=\"shiki\" data-ext=\"json\" style=\"--shiki-light:#383A42;--shiki-dark:#abb2bf;--shiki-light-bg:#FAFAFA;--shiki-dark-bg:#282c34\"><pre class=\"shiki shiki-themes one-light one-dark-pro vp-code\"><code class=\"language-json\"><span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">{</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\">    \"configurations\"</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">: [</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">        {</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\">            \"name\"</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">: </span><span style=\"--shiki-light:#50A14F;--shiki-dark:#98C379\">\"GBDK_VSC\"</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">,</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\">            \"includePath\"</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">: [</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#50A14F;--shiki-dark:#98C379\">                \"${GBDKDIR}/include/**\"</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">            ],</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\">            \"defines\"</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">: [],</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\">            \"macFrameworkPath\"</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">: [],</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\">            \"compilerPath\"</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">: </span><span style=\"--shiki-light:#50A14F;--shiki-dark:#98C379\">\"${GBDKDIR}/bin/lcc\"</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">,</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\">            \"cStandard\"</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">: </span><span style=\"--shiki-light:#50A14F;--shiki-dark:#98C379\">\"gnu99\"</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">        }</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">    ],</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\">    \"version\"</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">: </span><span style=\"--shiki-light:#986801;--shiki-dark:#D19A66\">4</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">}</span></span></code></pre>\n<div class=\"line-numbers\" aria-hidden=\"true\" style=\"counter-reset:line-number 0\"><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div></div></div><p>Copy the exported <code>Smile.h</code> and <code>Smile.c</code> files into <code>first-sprite</code>. Then create the main program, <code>FirstSprite.c</code>, in that directory:</p>\n<div class=\"language-c line-numbers-mode\" data-highlighter=\"shiki\" data-ext=\"c\" style=\"--shiki-light:#383A42;--shiki-dark:#abb2bf;--shiki-light-bg:#FAFAFA;--shiki-dark-bg:#282c34\"><pre class=\"shiki shiki-themes one-light one-dark-pro vp-code\"><code class=\"language-c\"><span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">#include</span><span style=\"--shiki-light:#50A14F;--shiki-dark:#98C379\"> &#x3C;gb/gb.h></span></span>\n<span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">#include</span><span style=\"--shiki-light:#50A14F;--shiki-dark:#98C379\"> &#x3C;stdio.h></span></span>\n<span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">#include</span><span style=\"--shiki-light:#50A14F;--shiki-dark:#98C379\"> \"Smile.h\"</span></span>\n<span class=\"line\"></span>\n<span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">void</span><span style=\"--shiki-light:#4078F2;--shiki-dark:#61AFEF\"> main</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">()</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">{</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#A0A1A7;--shiki-light-font-style:italic;--shiki-dark:#7F848E;--shiki-dark-font-style:italic\">    // Copy one tile from Smile to sprite tile slot 0.</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#4078F2;--shiki-dark:#61AFEF\">    set_sprite_data</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">(</span><span style=\"--shiki-light:#986801;--shiki-dark:#D19A66\">0</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">, </span><span style=\"--shiki-light:#986801;--shiki-dark:#D19A66\">1</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">, Smile);</span></span>\n<span class=\"line\"></span>\n<span class=\"line\"><span style=\"--shiki-light:#A0A1A7;--shiki-light-font-style:italic;--shiki-dark:#7F848E;--shiki-dark-font-style:italic\">    // Use tile 0 for hardware sprite 0.</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#4078F2;--shiki-dark:#61AFEF\">    set_sprite_tile</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">(</span><span style=\"--shiki-light:#986801;--shiki-dark:#D19A66\">0</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">, </span><span style=\"--shiki-light:#986801;--shiki-dark:#D19A66\">0</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">);</span></span>\n<span class=\"line\"></span>\n<span class=\"line\"><span style=\"--shiki-light:#A0A1A7;--shiki-light-font-style:italic;--shiki-dark:#7F848E;--shiki-dark-font-style:italic\">    // Enable the sprite layer through bit 1 of LCDC.</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">    SHOW_SPRITES;</span></span>\n<span class=\"line\"></span>\n<span class=\"line\"><span style=\"--shiki-light:#A0A1A7;--shiki-light-font-style:italic;--shiki-dark:#7F848E;--shiki-dark-font-style:italic\">    // Move hardware sprite 0 near the centre of the screen.</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#4078F2;--shiki-dark:#61AFEF\">    move_sprite</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">(</span><span style=\"--shiki-light:#986801;--shiki-dark:#D19A66\">0</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">, </span><span style=\"--shiki-light:#986801;--shiki-dark:#D19A66\">84</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">, </span><span style=\"--shiki-light:#986801;--shiki-dark:#D19A66\">78</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">);</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">}</span></span></code></pre>\n<div class=\"line-numbers\" aria-hidden=\"true\" style=\"counter-reset:line-number 0\"><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div></div></div><p>The second argument of <a href=\"https://gbdk.org/docs/api/gb_8h.html\" target=\"_blank\" rel=\"noopener noreferrer\"><code>set_sprite_data</code></a> is the <strong>number of tiles</strong>, so we pass <code>1</code> for this one-tile image.</p>\n<p>Next, create a <code>Makefile</code>. Make describes how source files are compiled and linked, so we can repeat the build without typing the full compiler command each time:</p>\n<div class=\"language-makefile line-numbers-mode\" data-highlighter=\"shiki\" data-ext=\"makefile\" style=\"--shiki-light:#383A42;--shiki-dark:#abb2bf;--shiki-light-bg:#FAFAFA;--shiki-dark-bg:#282c34\"><pre class=\"shiki shiki-themes one-light one-dark-pro vp-code\"><code class=\"language-makefile\"><span class=\"line\"><span style=\"--shiki-light:#A0A1A7;--shiki-light-font-style:italic;--shiki-dark:#7F848E;--shiki-dark-font-style:italic\"># Path to the LCC compiler</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\">CC</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">  =</span><span style=\"--shiki-light:#50A14F;--shiki-dark:#98C379\"> $(</span><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\">GBDKDIR</span><span style=\"--shiki-light:#50A14F;--shiki-dark:#98C379\">)</span><span style=\"--shiki-light:#383A42;--shiki-dark:#E5C07B\">/bin/lcc</span></span>\n<span class=\"line\"></span>\n<span class=\"line\"><span style=\"--shiki-light:#A0A1A7;--shiki-light-font-style:italic;--shiki-dark:#7F848E;--shiki-dark-font-style:italic\"># Path to SameBoy</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\">EMU</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\"> =</span><span style=\"--shiki-light:#383A42;--shiki-dark:#E5C07B\"> /Applications/SameBoy.app/Contents/MacOS/SameBoy</span></span>\n<span class=\"line\"></span>\n<span class=\"line\"><span style=\"--shiki-light:#A0A1A7;--shiki-light-font-style:italic;--shiki-dark:#7F848E;--shiki-dark-font-style:italic\"># Compile the sources and link FirstSprite.gb</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#4078F2;--shiki-dark:#61AFEF\">all</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">:</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#50A14F;--shiki-dark:#98C379\">\t$(</span><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\">CC</span><span style=\"--shiki-light:#50A14F;--shiki-dark:#98C379\">)</span><span style=\"--shiki-light:#383A42;--shiki-dark:#E5C07B\"> -Wa-l -Wl-m -Wl-j -o FirstSprite.gb Smile.c FirstSprite.c</span></span>\n<span class=\"line\"></span>\n<span class=\"line\"><span style=\"--shiki-light:#A0A1A7;--shiki-light-font-style:italic;--shiki-dark:#7F848E;--shiki-dark-font-style:italic\"># Build the ROM, then run it in SameBoy</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#4078F2;--shiki-dark:#61AFEF\">run</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">:</span><span style=\"--shiki-light:#383A42;--shiki-dark:#E06C75\"> all</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#50A14F;--shiki-dark:#98C379\">\t$(</span><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\">EMU</span><span style=\"--shiki-light:#50A14F;--shiki-dark:#98C379\">)</span><span style=\"--shiki-light:#383A42;--shiki-dark:#E5C07B\"> FirstSprite.gb</span></span>\n<span class=\"line\"></span>\n<span class=\"line\"><span style=\"--shiki-light:#A0A1A7;--shiki-light-font-style:italic;--shiki-dark:#7F848E;--shiki-dark-font-style:italic\"># Remove intermediate files and generated output</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#4078F2;--shiki-dark:#61AFEF\">clean</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">:</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#E5C07B\">\trm -f *.o *.lst *.map *.gb *.ihx *.sym *.cdb *.adb *.asm *.noi</span></span></code></pre>\n<div class=\"line-numbers\" aria-hidden=\"true\" style=\"counter-reset:line-number 0\"><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div></div></div><p>The available commands are:</p>\n<ul>\n<li><code>make</code>: runs the first target, <code>all</code>.</li>\n<li><code>make all</code>: compiles and links the ROM, <code>FirstSprite.gb</code>.</li>\n<li><code>make run</code>: builds the ROM and opens it in SameBoy.</li>\n<li><code>make clean</code>: removes intermediate files and generated output.</li>\n</ul>\n<p>Run <code>make run</code> to build, link, and launch the program. The result should look like this:</p>\n<figure><img src=\"https://zzxzzk115.github.io/blog/images/game-dev/retro/gameboy/gbdk/successfully_showed_first_sprite.png\" alt=\"The first sprite displayed on screen\" tabindex=\"0\" loading=\"lazy\"><figcaption>The first sprite displayed on screen</figcaption></figure>\n<p>Use <code>make clean</code> to return to the source files and Makefile.</p>\n<div class=\"hint-container tip\">\n<p class=\"hint-container-title\">Tips</p>\n<p>The example sources are in the <a href=\"https://github.com/zzxzzk115/blog/tree/master/src/.vuepress/public/src/gb-dev/\" target=\"_blank\" rel=\"noopener noreferrer\"><code>gb-dev</code> directory</a>.</p>\n</div>\n",
      "image": "https://zzxzzk115.github.io/blog/images/game-dev/retro/gameboy/gbdk/gbtd_interface_01.png",
      "date_published": "2022-12-20T00:00:00.000Z",
      "date_modified": "2026-10-17T16:08:05.000Z",
      "authors": [
        {
          "name": "Lazy_V"
        }
      ],
      "tags": [
        "Game Development"
      ]
    },
    {
      "title": "Setting Up GBDK",
      "url": "https://zzxzzk115.github.io/blog/game-dev/retro/gameboy/gbdk/002-gbdk-preparation.html",
      "id": "https://zzxzzk115.github.io/blog/game-dev/retro/gameboy/gbdk/002-gbdk-preparation.html",
      "summary": "GBDK is open source, with release builds available on GitHub. I was using macOS when I wrote this tutorial, so I will start with setting up GBDK on macOS and compiling a Hello W...",
      "content_html": "<p>GBDK is open source, with release builds available on GitHub. I was using macOS when I wrote this tutorial, so I will start with setting up GBDK on macOS and compiling a Hello World program. The general process is similar on Linux and Windows, although the installation details differ. Feel free to leave a comment if you run into trouble.</p>\n<!-- more -->\n<div class=\"hint-container info\">\n<p class=\"hint-container-title\">Versions used in this tutorial</p>\n<p>This tutorial describes my December 2022 setup. The release links and versions below are retained from that setup; use the upstream release pages when choosing a version for a new installation.</p>\n</div>\n<h2>Download GBDK</h2>\n<p>At the time of writing, the stable version was v4.1.1. <a href=\"https://github.com/gbdk-2020/gbdk-2020/releases/download/4.1.1/gbdk-macos.tar.gz\" target=\"_blank\" rel=\"noopener noreferrer\">Download the macOS archive</a>, or find other versions on the <a href=\"https://github.com/gbdk-2020/gbdk-2020/releases\" target=\"_blank\" rel=\"noopener noreferrer\">releases page</a>.</p>\n<h2>Directory structure</h2>\n<p>Extract the archive to get a directory named <code>gbdk</code>. Its contents include:</p>\n<ul>\n<li>\n <code>bin/</code>: prebuilt executable tools</li>\n<li>\n <code>include/</code>: header files</li>\n<li>\n <code>lib/</code>: libraries</li>\n<li>\n <code>examples/</code>: example programs</li>\n<li>\n <code>licenses/</code>: licences</li>\n<li>\n <code>gbdk_manual.pdf</code>: the GBDK manual</li>\n<li>\n <code>sdccman.pdf</code>: the SDCC manual</li>\n<li>\n <code>ChangeLog</code>: release changes</li>\n<li>\n <code>README</code>: introductory information</li>\n</ul>\n<p>Next, move this directory to a suitable location and configure the environment.</p>\n<h2>Install GBDK and set environment variables</h2>\n<p>For example, copy the directory to <code>/opt/gbdk</code>:</p>\n<div class=\"language-bash line-numbers-mode\" data-highlighter=\"shiki\" data-ext=\"bash\" style=\"--shiki-light:#383A42;--shiki-dark:#abb2bf;--shiki-light-bg:#FAFAFA;--shiki-dark-bg:#282c34\"><pre class=\"shiki shiki-themes one-light one-dark-pro vp-code\"><code class=\"language-bash\"><span class=\"line\"><span style=\"--shiki-light:#4078F2;--shiki-dark:#61AFEF\">sudo</span><span style=\"--shiki-light:#50A14F;--shiki-dark:#98C379\"> cp</span><span style=\"--shiki-light:#986801;--shiki-dark:#D19A66\"> -r</span><span style=\"--shiki-light:#50A14F;--shiki-dark:#98C379\"> gbdk</span><span style=\"--shiki-light:#50A14F;--shiki-dark:#98C379\"> /opt/gbdk</span></span></code></pre>\n<div class=\"line-numbers\" aria-hidden=\"true\" style=\"counter-reset:line-number 0\"><div class=\"line-number\"></div></div></div><p>Then set the environment variable.</p>\n<div class=\"hint-container tip\">\n<p class=\"hint-container-title\">Tips</p>\n<p>To make it persistent, add the setting to <code>/etc/profile</code> or your shell's configuration file. Choose the appropriate file; you do not need to update all three.</p>\n</div>\n\n<div class=\"hint-container info\">\n<p class=\"hint-container-title\">Info</p>\n<p>The commands in this tutorial use <code>GBDKDIR</code>. You can also add its <code>bin</code> directory to <code>PATH</code> to invoke the tools without their full paths.</p>\n</div>\n<h2>Prepare the GBDK versions of GBTD and GBMB</h2>\n<p>GBTD (Game Boy Tile Designer) and GBMB (Game Boy Map Builder) are used for tile graphics and tile maps. GBTD draws the tiles; GBMB arranges those tiles into a map.</p>\n<p>We will use both tools later. <a href=\"https://github.com/gbdk-2020/GBTD_GBMB/releases/download/2.4.5/GBTD_GBMB_release.zip\" target=\"_blank\" rel=\"noopener noreferrer\">Download the 2.4.5 archive</a>, or choose a version from the <a href=\"https://github.com/gbdk-2020/GBTD_GBMB/releases\" target=\"_blank\" rel=\"noopener noreferrer\">releases page</a>.</p>\n<p>Extract it to get a <code>GBTD_GBMB_release</code> directory containing <code>GBTD</code> and <code>GBMB</code>. Create a <code>tools</code> directory inside <code>gbdk</code>, then copy the tool directories into it. On macOS or Linux:</p>\n<div class=\"language-bash line-numbers-mode\" data-highlighter=\"shiki\" data-ext=\"bash\" style=\"--shiki-light:#383A42;--shiki-dark:#abb2bf;--shiki-light-bg:#FAFAFA;--shiki-dark-bg:#282c34\"><pre class=\"shiki shiki-themes one-light one-dark-pro vp-code\"><code class=\"language-bash\"><span class=\"line\"><span style=\"--shiki-light:#4078F2;--shiki-dark:#61AFEF\">sudo</span><span style=\"--shiki-light:#50A14F;--shiki-dark:#98C379\"> mkdir</span><span style=\"--shiki-light:#986801;--shiki-dark:#D19A66\"> -p</span><span style=\"--shiki-light:#50A14F;--shiki-dark:#98C379\"> \"</span><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\">$GBDKDIR</span><span style=\"--shiki-light:#50A14F;--shiki-dark:#98C379\">/tools\"</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#0184BC;--shiki-dark:#56B6C2\">cd</span><span style=\"--shiki-light:#50A14F;--shiki-dark:#98C379\"> GBTD_GBMB_release</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#4078F2;--shiki-dark:#61AFEF\">sudo</span><span style=\"--shiki-light:#50A14F;--shiki-dark:#98C379\"> cp</span><span style=\"--shiki-light:#986801;--shiki-dark:#D19A66\"> -r</span><span style=\"--shiki-light:#50A14F;--shiki-dark:#98C379\"> GBTD</span><span style=\"--shiki-light:#50A14F;--shiki-dark:#98C379\"> \"</span><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\">$GBDKDIR</span><span style=\"--shiki-light:#50A14F;--shiki-dark:#98C379\">/tools/\"</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#4078F2;--shiki-dark:#61AFEF\">sudo</span><span style=\"--shiki-light:#50A14F;--shiki-dark:#98C379\"> cp</span><span style=\"--shiki-light:#986801;--shiki-dark:#D19A66\"> -r</span><span style=\"--shiki-light:#50A14F;--shiki-dark:#98C379\"> GBMB</span><span style=\"--shiki-light:#50A14F;--shiki-dark:#98C379\"> \"</span><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\">$GBDKDIR</span><span style=\"--shiki-light:#50A14F;--shiki-dark:#98C379\">/tools/\"</span></span></code></pre>\n<div class=\"line-numbers\" aria-hidden=\"true\" style=\"counter-reset:line-number 0\"><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div></div></div><div class=\"hint-container warning\">\n<p class=\"hint-container-title\">Configuration file permissions</p>\n<p>If the tools cannot save their <code>.ini</code> settings, check the files' ownership and give your account write access to those files. The original setup used a blanket <code>chmod 777</code>; that is unnecessary. A user-owned copy of the tools is another option when a system-wide installation is not needed.</p>\n</div>\n<div class=\"hint-container tip\">\n<p class=\"hint-container-title\">Running the Windows tools</p>\n<p>On macOS and Linux, these tools need a compatible Wine installation. Wine runs Windows applications by providing compatible implementations of Windows APIs.</p>\n</div>\n\n<h3>Launch GBTD and GBMB with Wine</h3>\n<p>Once Wine is configured, run:</p>\n<div class=\"language-bash line-numbers-mode\" data-highlighter=\"shiki\" data-ext=\"bash\" style=\"--shiki-light:#383A42;--shiki-dark:#abb2bf;--shiki-light-bg:#FAFAFA;--shiki-dark-bg:#282c34\"><pre class=\"shiki shiki-themes one-light one-dark-pro vp-code\"><code class=\"language-bash\"><span class=\"line\"><span style=\"--shiki-light:#4078F2;--shiki-dark:#61AFEF\">wine</span><span style=\"--shiki-light:#50A14F;--shiki-dark:#98C379\"> \"</span><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\">$GBDKDIR</span><span style=\"--shiki-light:#50A14F;--shiki-dark:#98C379\">/tools/GBTD/gbtd.exe\"</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#4078F2;--shiki-dark:#61AFEF\">wine</span><span style=\"--shiki-light:#50A14F;--shiki-dark:#98C379\"> \"</span><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\">$GBDKDIR</span><span style=\"--shiki-light:#50A14F;--shiki-dark:#98C379\">/tools/GBMB/gbmb.exe\"</span></span></code></pre>\n<div class=\"line-numbers\" aria-hidden=\"true\" style=\"counter-reset:line-number 0\"><div class=\"line-number\"></div><div class=\"line-number\"></div></div></div><p>For convenience, add aliases to your shell configuration. For example, in <code>~/.zshrc</code>:</p>\n<div class=\"language-bash line-numbers-mode\" data-highlighter=\"shiki\" data-ext=\"bash\" style=\"--shiki-light:#383A42;--shiki-dark:#abb2bf;--shiki-light-bg:#FAFAFA;--shiki-dark-bg:#282c34\"><pre class=\"shiki shiki-themes one-light one-dark-pro vp-code\"><code class=\"language-bash\"><span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">alias</span><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\"> gbtd</span><span style=\"--shiki-light:#383A42;--shiki-dark:#56B6C2\">=</span><span style=\"--shiki-light:#50A14F;--shiki-dark:#98C379\">'wine \"$GBDKDIR/tools/GBTD/gbtd.exe\"'</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">alias</span><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\"> gbmb</span><span style=\"--shiki-light:#383A42;--shiki-dark:#56B6C2\">=</span><span style=\"--shiki-light:#50A14F;--shiki-dark:#98C379\">'wine \"$GBDKDIR/tools/GBMB/gbmb.exe\"'</span></span></code></pre>\n<div class=\"line-numbers\" aria-hidden=\"true\" style=\"counter-reset:line-number 0\"><div class=\"line-number\"></div><div class=\"line-number\"></div></div></div><p>Use <code>~/.bashrc</code> for Bash, or the appropriate configuration file for your shell. Open a new shell after editing it.</p>\n<h2>Prepare an emulator: SameBoy</h2>\n<p>I chose <a href=\"https://github.com/LIJI32/SameBoy\" target=\"_blank\" rel=\"noopener noreferrer\">SameBoy</a>, an open-source, cross-platform emulator with debugging features that are useful during development.</p>\n<p>Choose a build for your platform from the <a href=\"https://sameboy.github.io/downloads/\" target=\"_blank\" rel=\"noopener noreferrer\">download page</a>. For this tutorial, I used <a href=\"https://github.com/LIJI32/SameBoy/releases/download/v0.15.8/sameboy_cocoa_v0.15.8.zip\" target=\"_blank\" rel=\"noopener noreferrer\">SameBoy v0.15.8 for macOS</a>. Extract the app and drag it into <code>Applications</code>.</p>\n<h2>Hello, world!</h2>\n<p>Let's write our first program: display a line of text on the Game Boy screen.</p>\n<h3>Write the source</h3>\n<p>Create <code>helloworld.c</code>:</p>\n<div class=\"language-c line-numbers-mode\" data-highlighter=\"shiki\" data-ext=\"c\" style=\"--shiki-light:#383A42;--shiki-dark:#abb2bf;--shiki-light-bg:#FAFAFA;--shiki-dark-bg:#282c34\"><pre class=\"shiki shiki-themes one-light one-dark-pro vp-code\"><code class=\"language-c\"><span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">#include</span><span style=\"--shiki-light:#50A14F;--shiki-dark:#98C379\"> &#x3C;gb/gb.h></span></span>\n<span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">#include</span><span style=\"--shiki-light:#50A14F;--shiki-dark:#98C379\"> &#x3C;stdio.h></span></span>\n<span class=\"line\"></span>\n<span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">void</span><span style=\"--shiki-light:#4078F2;--shiki-dark:#61AFEF\"> main</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">()</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">{</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#4078F2;--shiki-dark:#61AFEF\">    printf</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">(</span><span style=\"--shiki-light:#50A14F;--shiki-dark:#98C379\">\"HELLO, WORLD!\"</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">);</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">}</span></span></code></pre>\n<div class=\"line-numbers\" aria-hidden=\"true\" style=\"counter-reset:line-number 0\"><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div></div></div><h3>Compile from the command line</h3>\n<p>Open a terminal in the directory containing <code>helloworld.c</code> and run:</p>\n<div class=\"language-bash line-numbers-mode\" data-highlighter=\"shiki\" data-ext=\"bash\" style=\"--shiki-light:#383A42;--shiki-dark:#abb2bf;--shiki-light-bg:#FAFAFA;--shiki-dark-bg:#282c34\"><pre class=\"shiki shiki-themes one-light one-dark-pro vp-code\"><code class=\"language-bash\"><span class=\"line\"><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\">$GBDKDIR</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">/bin/lcc -Wa-l -Wl-m -Wl-j -o helloworld.gb helloworld.c</span></span></code></pre>\n<div class=\"line-numbers\" aria-hidden=\"true\" style=\"counter-reset:line-number 0\"><div class=\"line-number\"></div></div></div><p>This produces <code>helloworld.gb</code>, a ROM file that can be opened in an emulator.</p>\n<h3>Open the ROM in SameBoy</h3>\n<figure><img src=\"https://zzxzzk115.github.io/blog/images/game-dev/retro/gameboy/gbdk/helloworld_samboy.png\" alt=\"Hello, world! in SameBoy\" tabindex=\"0\" loading=\"lazy\"><figcaption>Hello, world! in SameBoy</figcaption></figure>\n<div class=\"hint-container tip\">\n<p class=\"hint-container-title\">Tips</p>\n<p>You can also add an alias for SameBoy to your shell configuration:</p>\n<div class=\"language-bash line-numbers-mode\" data-highlighter=\"shiki\" data-ext=\"bash\" style=\"--shiki-light:#383A42;--shiki-dark:#abb2bf;--shiki-light-bg:#FAFAFA;--shiki-dark-bg:#282c34\"><pre class=\"shiki shiki-themes one-light one-dark-pro vp-code\"><code class=\"language-bash\"><span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">alias</span><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\"> sameboy</span><span style=\"--shiki-light:#383A42;--shiki-dark:#56B6C2\">=</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">/Applications/SameBoy.app/Contents/MacOS/SameBoy</span></span></code></pre>\n<div class=\"line-numbers\" aria-hidden=\"true\" style=\"counter-reset:line-number 0\"><div class=\"line-number\"></div></div></div><p>Then open the ROM directly from the terminal:</p>\n<div class=\"language-bash line-numbers-mode\" data-highlighter=\"shiki\" data-ext=\"bash\" style=\"--shiki-light:#383A42;--shiki-dark:#abb2bf;--shiki-light-bg:#FAFAFA;--shiki-dark-bg:#282c34\"><pre class=\"shiki shiki-themes one-light one-dark-pro vp-code\"><code class=\"language-bash\"><span class=\"line\"><span style=\"--shiki-light:#4078F2;--shiki-dark:#61AFEF\">sameboy</span><span style=\"--shiki-light:#50A14F;--shiki-dark:#98C379\"> helloworld.gb</span></span></code></pre>\n<div class=\"line-numbers\" aria-hidden=\"true\" style=\"counter-reset:line-number 0\"><div class=\"line-number\"></div></div></div></div>\n<p>Congratulations — you have built and run your first Game Boy program! 🎉</p>\n",
      "image": "https://zzxzzk115.github.io/blog/images/game-dev/retro/gameboy/gbdk/helloworld_samboy.png",
      "date_published": "2022-12-18T19:10:00.000Z",
      "date_modified": "2026-10-17T16:08:05.000Z",
      "authors": [
        {
          "name": "Lazy_V"
        }
      ],
      "tags": [
        "Game Development"
      ]
    },
    {
      "title": "An Introduction to GBDK",
      "url": "https://zzxzzk115.github.io/blog/game-dev/retro/gameboy/gbdk/001-gbdk-intro.html",
      "id": "https://zzxzzk115.github.io/blog/game-dev/retro/gameboy/gbdk/001-gbdk-intro.html",
      "summary": "Assembly language is a common choice for GB/GBC development. However, starting with it requires learning the hardware and instruction set together, which can be a substantial ba...",
      "content_html": "<p>Assembly language is a common choice for GB/GBC development. However, starting with it requires learning the hardware and instruction set together, which can be a substantial barrier for a beginner.</p>\n<p>For this series, we will use a higher-level language: C. GBDK provides the tools and libraries needed to write C programs for the Game Boy and Game Boy Color.</p>\n<p><a href=\"https://github.com/gbdk-2020/gbdk-2020\" target=\"_blank\" rel=\"noopener noreferrer\">GBDK</a>, the Game Boy Development Kit, includes a toolchain based on SDCC, together with an assembler, linker, and libraries for the supported hardware. The Game Boy CPU is the Sharp SM83, with an instruction set related to the Intel 8080 and Z80; it is not a full Z80, so Z80 code and libraries are not generally interchangeable with Game Boy code.</p>\n<p>GBDK bundles the tools we need to build a ROM. Next, let's <a href=\"https://zzxzzk115.github.io/blog/game-dev/retro/gameboy/gbdk/002-gbdk-preparation.html\" target=\"_blank\">set up the development environment</a>.</p>\n",
      "date_published": "2022-12-18T19:05:00.000Z",
      "date_modified": "2026-10-17T16:08:05.000Z",
      "authors": [
        {
          "name": "Lazy_V"
        }
      ],
      "tags": [
        "Game Development"
      ]
    },
    {
      "title": "GB/GBC Game Development — Introduction",
      "url": "https://zzxzzk115.github.io/blog/game-dev/retro/gameboy/intro.html",
      "id": "https://zzxzzk115.github.io/blog/game-dev/retro/gameboy/intro.html",
      "summary": "Before we begin Nintendo's Game Boy was popular around the world, but I never had one as a child. When I learned about it later, I became fascinated by it and wanted to make gam...",
      "content_html": "<div class=\"hint-container info\">\n<p class=\"hint-container-title\">Before we begin</p>\n<p>Nintendo's Game Boy was popular around the world, but I never had one as a child. When I learned about it later, I became fascinated by it and wanted to make games that could run on the hardware.</p>\n</div>\n<!-- more -->\n<h2>How I got into GB/GBC development</h2>\n<p>In 2018, I discovered <a href=\"https://github.com/gbdk-2020/gbdk-2020\" target=\"_blank\" rel=\"noopener noreferrer\">GBDK</a>. Using it and the C programming I already knew, I made a few small games and demos. They remained unfinished, so I do not plan to show them here.</p>\n<p>In 2020, I learned about <a href=\"https://github.com/chrismaltby/gb-studio\" target=\"_blank\" rel=\"noopener noreferrer\">GB Studio</a>, a tool that makes GB/GBC game development accessible without requiring programming experience.</p>\n<p>In 2021, during the pandemic, I felt particularly motivated to create something. I used GB Studio to make my own GBC version of Cat Mario: <a href=\"https://zzxzzk115.github.io/blog/game-dev/001-games-gallery.html#catmario-gb\" target=\"_blank\">CatMario-GB</a>.</p>\n<h2>Let's start developing for GB/GBC</h2>\n<p>I would like to share what I have learned in a series of tutorials on <strong>modern</strong> GB/GBC development.</p>\n<p>I will start with the more code-oriented GBDK toolchain. GB Studio is easier to get started with, so I can cover it later.</p>\n<p>Rather than beginning with a long explanation of all the hardware, I will introduce individual hardware features, their settings, and the underlying principles as we need them to produce something on screen.</p>\n<p>Start here:</p>\n<ul>\n<li><a href=\"https://zzxzzk115.github.io/blog/game-dev/retro/gameboy/gbdk/001-gbdk-intro.html\" target=\"_blank\">Developing with GBDK</a></li>\n</ul>\n",
      "date_published": "2022-12-18T19:00:00.000Z",
      "date_modified": "2026-10-17T16:08:05.000Z",
      "authors": [
        {
          "name": "Lazy_V"
        }
      ],
      "tags": [
        "Game Development"
      ]
    },
    {
      "title": "The algorithm framework for solving DP problems",
      "url": "https://zzxzzk115.github.io/blog/posts/algorithms/dynamic-programming/framework.html",
      "id": "https://zzxzzk115.github.io/blog/posts/algorithms/dynamic-programming/framework.html",
      "summary": "Dynamic Programming problems are the most complicated problems in algorithms. However, it is actually simple to solve if you understand the key concepts and the main algorithm f...",
      "content_html": "<p>Dynamic Programming problems are the most complicated problems in algorithms. However, it is actually simple to solve if you understand the key concepts and the main algorithm framework of DP.</p>\n<!-- more -->\n<h2>What is Dynamic Programming (DP) ?</h2>\n<p>Dynamic Programming (DP) is a method for solving complex problems by breaking them down into smaller subproblems. It is a bottom-up approach, meaning it starts with solving the smaller subproblems and then uses those solutions to build up to a solution for the larger problem.</p>\n<p>To solve a problem with DP, the problem must have the following properties:</p>\n<ol>\n<li>\n<p>Optimal substructure: The optimal solution to a problem can be constructed from optimal solutions to its subproblems.</p>\n</li>\n<li>\n<p>Overlapping subproblems: A problem can be broken down into subproblems that are reused multiple times.</p>\n</li>\n</ol>\n<h2>A classic DP problem : Fibonacci</h2>\n<p>For an instance, when we calculate the Fibonacci sequence, we can use DP.</p>\n<div class=\"hint-container tip\">\n<p class=\"hint-container-title\">Tips</p>\n<p>The Fibonacci sequence is a series of numbers where each number is the sum of the two preceding numbers, starting with 0 and 1. The sequence goes as follows: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, and so on. The sequence is named after Leonardo of Pisa, who was known as Fibonacci. He introduced the sequence to Western European mathematics in his book &quot;Liber Abaci&quot; in the year 1202.</p>\n</div>\n<p>In general, for calculating the Fibonacci sequence, we use recursion functions, like the following:</p>\n<div class=\"language-cpp line-numbers-mode\" data-highlighter=\"shiki\" data-ext=\"cpp\" style=\"--shiki-light:#383A42;--shiki-dark:#abb2bf;--shiki-light-bg:#FAFAFA;--shiki-dark-bg:#282c34\"><pre class=\"shiki shiki-themes one-light one-dark-pro vp-code\"><code class=\"language-cpp\"><span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">int</span><span style=\"--shiki-light:#4078F2;--shiki-dark:#61AFEF\"> Fibonacci</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">(</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">int</span><span style=\"--shiki-light:#383A42;--shiki-light-font-style:inherit;--shiki-dark:#E06C75;--shiki-dark-font-style:italic\"> n</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">) {</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">  if</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\"> (</span><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\">n</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> ==</span><span style=\"--shiki-light:#986801;--shiki-dark:#D19A66\"> 0</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">) {</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">\t\treturn</span><span style=\"--shiki-light:#986801;--shiki-dark:#D19A66\"> 0</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">;</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">\t}</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">\tif</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\"> (</span><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\">n</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> ==</span><span style=\"--shiki-light:#986801;--shiki-dark:#D19A66\"> 1</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#56B6C2\"> ||</span><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\"> n</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> ==</span><span style=\"--shiki-light:#986801;--shiki-dark:#D19A66\"> 2</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">) {</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">\t\treturn</span><span style=\"--shiki-light:#986801;--shiki-dark:#D19A66\"> 1</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">;</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">\t}</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">\treturn</span><span style=\"--shiki-light:#4078F2;--shiki-dark:#61AFEF\"> Fibonacci</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">(</span><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\">n</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> -</span><span style=\"--shiki-light:#986801;--shiki-dark:#D19A66\"> 1</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">) </span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">+</span><span style=\"--shiki-light:#4078F2;--shiki-dark:#61AFEF\"> Fibonacci</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">(</span><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\">n</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> -</span><span style=\"--shiki-light:#986801;--shiki-dark:#D19A66\"> 2</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">);</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">}</span></span></code></pre>\n<div class=\"line-numbers\" aria-hidden=\"true\" style=\"counter-reset:line-number 0\"><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div></div></div><p>The technique we use is just Recursion, not DP.</p>\n<p>The function call tree has a lot of nodes, but many of them are duplicated.</p>\n<p>I have an equation:</p>\n<p>DP = Recursion + Memoization OR Tabulation + optional improvements.</p>\n<p>What does it mean?</p>\n<p>Well, Memoization and tabulation are two techniques used to improve the performance of algorithms that use Dynamic Programming.</p>\n<p>Memoization is a technique that involves storing the results of intermediate calculations in a table, so that they can be reused later. This can help to reduce the overall time complexity of the algorithm by avoiding the need to recalculate the same subproblems multiple times. It's top-bottom.</p>\n<p>Tabulation, on the other hand, is a technique that involves storing the final results of all the subproblems in a table. This allows the algorithm to avoid recomputing the solutions to the subproblems and simply look up the pre-computed results in the table. It's bottom-up.</p>\n<p>Both memoization and tabulation can be used to speed up Dynamic Programming algorithms. The choice between the two techniques often depends on the specific problem being solved and the amount of available memory.</p>\n<h3>Using Memoization</h3>\n<p>To use Memoization, we could define a look-up table or a cache table for saving calculated results. To define that table, we generally use a hash table.</p>\n<p>In C++, we will use std::unordered_map.</p>\n<p>For example, we can use Memoization to solve the Fibonacci problem:</p>\n<div class=\"language-cpp line-numbers-mode\" data-highlighter=\"shiki\" data-ext=\"cpp\" style=\"--shiki-light:#383A42;--shiki-dark:#abb2bf;--shiki-light-bg:#FAFAFA;--shiki-dark-bg:#282c34\"><pre class=\"shiki shiki-themes one-light one-dark-pro vp-code\"><code class=\"language-cpp\"><span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">std::</span><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\">unordered_map</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">&#x3C;int</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">, </span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">int></span><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\"> memo</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">;</span></span>\n<span class=\"line\"></span>\n<span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">int</span><span style=\"--shiki-light:#4078F2;--shiki-dark:#61AFEF\"> Fibonacci</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">(</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">int</span><span style=\"--shiki-light:#383A42;--shiki-light-font-style:inherit;--shiki-dark:#E06C75;--shiki-dark-font-style:italic\"> n</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">) {</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">  if</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\"> (</span><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\">n</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> ==</span><span style=\"--shiki-light:#986801;--shiki-dark:#D19A66\"> 0</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">) {</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">\t\treturn</span><span style=\"--shiki-light:#986801;--shiki-dark:#D19A66\"> 0</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">;</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">\t}</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">\tif</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\"> (</span><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\">n</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> ==</span><span style=\"--shiki-light:#986801;--shiki-dark:#D19A66\"> 1</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#56B6C2\"> ||</span><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\"> n</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> ==</span><span style=\"--shiki-light:#986801;--shiki-dark:#D19A66\"> 2</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">) {</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">\t\treturn</span><span style=\"--shiki-light:#986801;--shiki-dark:#D19A66\"> 1</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">;</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">\t}</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">  if</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\"> (</span><span style=\"--shiki-light:#E45649;--shiki-dark:#E5C07B\">memo</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">.</span><span style=\"--shiki-light:#4078F2;--shiki-dark:#61AFEF\">count</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">(</span><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\">n</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">) </span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">></span><span style=\"--shiki-light:#986801;--shiki-dark:#D19A66\"> 0</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">) {</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">    return</span><span style=\"--shiki-light:#E45649;--shiki-dark:#E5C07B\"> memo</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">[</span><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\">n</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">];</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">  } </span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">else</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\"> {</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#E45649;--shiki-dark:#E5C07B\">    memo</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">[</span><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\">n</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">] </span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">=</span><span style=\"--shiki-light:#4078F2;--shiki-dark:#61AFEF\"> Fibonacci</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">(</span><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\">n</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> -</span><span style=\"--shiki-light:#986801;--shiki-dark:#D19A66\"> 1</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">) </span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">+</span><span style=\"--shiki-light:#4078F2;--shiki-dark:#61AFEF\"> Fibonacci</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">(</span><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\">n</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> -</span><span style=\"--shiki-light:#986801;--shiki-dark:#D19A66\"> 2</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">);</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">  }</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">\treturn</span><span style=\"--shiki-light:#E45649;--shiki-dark:#E5C07B\"> memo</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">[</span><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\">n</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">];</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">}</span></span></code></pre>\n<div class=\"line-numbers\" aria-hidden=\"true\" style=\"counter-reset:line-number 0\"><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div></div></div><p>Now, all the duplicated nodes are gone, we calculate <code>Fibonacci(i)</code> just one time.</p>\n<h3>Using Tabulation</h3>\n<p>We can also use Tabulation for solving the problem. To use Tabulation, we could define an array or a vector for saving results of sub-problems.</p>\n<p>In C++, we will use std::vector.</p>\n<p>Here is the implementation of Fibonacci by using Tabulation:</p>\n<div class=\"language-cpp line-numbers-mode\" data-highlighter=\"shiki\" data-ext=\"cpp\" style=\"--shiki-light:#383A42;--shiki-dark:#abb2bf;--shiki-light-bg:#FAFAFA;--shiki-dark-bg:#282c34\"><pre class=\"shiki shiki-themes one-light one-dark-pro vp-code\"><code class=\"language-cpp\"><span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">int</span><span style=\"--shiki-light:#4078F2;--shiki-dark:#61AFEF\"> Fibonacci</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">(</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">int</span><span style=\"--shiki-light:#383A42;--shiki-light-font-style:inherit;--shiki-dark:#E06C75;--shiki-dark-font-style:italic\"> n</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">) {</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">  if</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\"> (</span><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\">n</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> ==</span><span style=\"--shiki-light:#986801;--shiki-dark:#D19A66\"> 0</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">) {</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">\t\treturn</span><span style=\"--shiki-light:#986801;--shiki-dark:#D19A66\"> 0</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">;</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">\t}</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">\tif</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\"> (</span><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\">n</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> ==</span><span style=\"--shiki-light:#986801;--shiki-dark:#D19A66\"> 1</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#56B6C2\"> ||</span><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\"> n</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> ==</span><span style=\"--shiki-light:#986801;--shiki-dark:#D19A66\"> 2</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">) {</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">\t\treturn</span><span style=\"--shiki-light:#986801;--shiki-dark:#D19A66\"> 1</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">;</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">\t}</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">  std::</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">vector</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">&#x3C;</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">int</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">> </span><span style=\"--shiki-light:#4078F2;--shiki-dark:#61AFEF\">d</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">(</span><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\">n</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> +</span><span style=\"--shiki-light:#986801;--shiki-dark:#D19A66\"> 1</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">);</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">  for</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\"> (</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">int</span><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\"> i</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> =</span><span style=\"--shiki-light:#986801;--shiki-dark:#D19A66\"> 3</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">; </span><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\">i</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> &#x3C;=</span><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\"> n</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">; </span><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\">i</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">++</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">) {</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#E45649;--shiki-dark:#E5C07B\">    d</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">[</span><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\">i</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">] </span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">=</span><span style=\"--shiki-light:#E45649;--shiki-dark:#E5C07B\"> d</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">[</span><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\">i</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> -</span><span style=\"--shiki-light:#986801;--shiki-dark:#D19A66\"> 1</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">] </span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">+</span><span style=\"--shiki-light:#E45649;--shiki-dark:#E5C07B\"> d</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">[</span><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\">i</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> -</span><span style=\"--shiki-light:#986801;--shiki-dark:#D19A66\"> 2</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">];</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">  }</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">  return</span><span style=\"--shiki-light:#E45649;--shiki-dark:#E5C07B\"> d</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">[</span><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\">n</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">];</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">}</span></span></code></pre>\n<div class=\"line-numbers\" aria-hidden=\"true\" style=\"counter-reset:line-number 0\"><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div></div></div><h3>Optional improvements</h3>\n<p>There is an optional improvement called State Compression.</p>\n<p>State compression is a technique used in Dynamic Programming to reduce the amount of memory needed to store the intermediate results of a calculation. It involves representing the state of a subproblem using a smaller data structure, such as a bit vector or a hash table, instead of a larger data structure like an array or a matrix. This can help to reduce the space complexity of the algorithm and make it possible to solve larger problems or problems with more complex subproblems.</p>\n<p>In this case, we replace <code>d</code> with two integers: <code>pre</code> and <code>curr</code>:</p>\n<div class=\"language-cpp line-numbers-mode\" data-highlighter=\"shiki\" data-ext=\"cpp\" style=\"--shiki-light:#383A42;--shiki-dark:#abb2bf;--shiki-light-bg:#FAFAFA;--shiki-dark-bg:#282c34\"><pre class=\"shiki shiki-themes one-light one-dark-pro vp-code\"><code class=\"language-cpp\"><span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">int</span><span style=\"--shiki-light:#4078F2;--shiki-dark:#61AFEF\"> Fibonacci</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">(</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">int</span><span style=\"--shiki-light:#383A42;--shiki-light-font-style:inherit;--shiki-dark:#E06C75;--shiki-dark-font-style:italic\"> n</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">) {</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">  if</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\"> (</span><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\">n</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> ==</span><span style=\"--shiki-light:#986801;--shiki-dark:#D19A66\"> 0</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">) {</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">\t\treturn</span><span style=\"--shiki-light:#986801;--shiki-dark:#D19A66\"> 0</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">;</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">\t}</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">\tif</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\"> (</span><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\">n</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> ==</span><span style=\"--shiki-light:#986801;--shiki-dark:#D19A66\"> 1</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#56B6C2\"> ||</span><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\"> n</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> ==</span><span style=\"--shiki-light:#986801;--shiki-dark:#D19A66\"> 2</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">) {</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">\t\treturn</span><span style=\"--shiki-light:#986801;--shiki-dark:#D19A66\"> 1</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">;</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">\t}</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">  int</span><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\"> pre</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> =</span><span style=\"--shiki-light:#986801;--shiki-dark:#D19A66\"> 1</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">;</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">  int</span><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\"> curr</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> =</span><span style=\"--shiki-light:#986801;--shiki-dark:#D19A66\"> 1</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">;</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">  for</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\"> (</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">int</span><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\"> i</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> =</span><span style=\"--shiki-light:#986801;--shiki-dark:#D19A66\"> 3</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">; </span><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\">i</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> &#x3C;=</span><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\"> n</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">; </span><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\">i</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">++</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">) {</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">    int</span><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\"> sum</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> =</span><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\"> pre</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> +</span><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\"> curr</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">;</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\">    pre</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> =</span><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\"> curr</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">;</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\">    curr</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> =</span><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\"> sum</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">;</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">  }</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">  return</span><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\"> curr</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">;</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">}</span></span></code></pre>\n<div class=\"line-numbers\" aria-hidden=\"true\" style=\"counter-reset:line-number 0\"><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div></div></div><h2>Framework</h2>\n<ol>\n<li>\n<p>Find all the base cases.</p>\n<p>In Fibonacci problem, base cases are <code>n == 0</code> and <code>n == 1</code> and <code>n == 2</code>;</p>\n</li>\n<li>\n<p>Find all the states.</p>\n<p>In Fibonacci problem, states are all the non-negative numbers.</p>\n</li>\n<li>\n<p>Find the state transition equation.</p>\n<p>In Fibonacci problem, the state transition equation is : dp[i] = dp[i - 1] + dp[i - 2]</p>\n</li>\n</ol>\n<div class=\"hint-container tip\">\n<p class=\"hint-container-title\">Tips</p>\n<p>A state transition equation is a mathematical equation that describes how the state of a system changes over time. In the context of Dynamic Programming, a state transition equation is an equation that describes how the optimal solution to a problem can be constructed from the optimal solutions to its subproblems. By using a state transition equation, it is possible to solve a problem by breaking it down into smaller subproblems and then combining the solutions to those subproblems to find a solution to the larger problem.</p>\n</div>\n<ol start=\"4\">\n<li>Find selections and figure out how to define the DP table.</li>\n</ol>\n",
      "date_published": "2022-12-09T00:00:00.000Z",
      "date_modified": "2022-12-17T14:58:15.000Z",
      "authors": [
        {
          "name": "Lazy_V"
        }
      ],
      "tags": [
        "Algorithms"
      ]
    },
    {
      "title": "Deeply dive into static abstract interface methods in C# 11",
      "url": "https://zzxzzk115.github.io/blog/posts/programming-languages/csharp/static-abstract-members-in-interfaces.html",
      "id": "https://zzxzzk115.github.io/blog/posts/programming-languages/csharp/static-abstract-members-in-interfaces.html",
      "summary": "Static abstract interface method is a new feature in C# 11 (corresponding .NET 7.0). In this article, we are going to deeply dive into it, talk about why we need it, what it is ...",
      "content_html": "<p>Static abstract interface method is a new feature in C# 11 (corresponding .NET 7.0). In this article, we are going to deeply dive into it, talk about why we need it, what it is and how to use it.</p>\n<!-- more -->\n<h2>Why we need it</h2>\n<p>Let's recall our previous demands:</p>\n<ol>\n<li>\n<p>We hope to perform mathematical operations in generics, but the compiler can't know the runtime type of <code>T</code>, so it can't know whether <code>T</code> supports mathematical operations such as addition, subtraction, multiplication and division, so it can't implement code like the following:</p>\n<div class=\"language-csharp line-numbers-mode\" data-highlighter=\"shiki\" data-ext=\"csharp\" style=\"--shiki-light:#383A42;--shiki-dark:#abb2bf;--shiki-light-bg:#FAFAFA;--shiki-dark-bg:#282c34\"><pre class=\"shiki shiki-themes one-light one-dark-pro vp-code\"><code class=\"language-csharp\"><span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">public</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\"> T</span><span style=\"--shiki-light:#4078F2;--shiki-dark:#61AFEF\"> Add</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">&#x3C;</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">T</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">>(</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">T</span><span style=\"--shiki-light:#383A42;--shiki-dark:#E5C07B\"> a</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">, </span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">T</span><span style=\"--shiki-light:#383A42;--shiki-dark:#E5C07B\"> b</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">)</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">{</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">    return</span><span style=\"--shiki-light:#383A42;--shiki-dark:#E06C75\"> a</span><span style=\"--shiki-light:#383A42;--shiki-dark:#56B6C2\"> +</span><span style=\"--shiki-light:#383A42;--shiki-dark:#E06C75\"> b</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">;</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">}</span></span></code></pre>\n<div class=\"line-numbers\" aria-hidden=\"true\" style=\"counter-reset:line-number 0\"><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div></div></div></li>\n<li>\n<p>We hope that in some cases, <code>T</code>, as a type that can be determined at compile time, can call the public static method of <code>T</code>. However, the static interface method cannot be declared in the interface to allow us to operate <code>T.XXX()</code>; If only the static interface method could be declared in the interface. We used to dream about implementing code like the following：</p>\n<div class=\"language-csharp line-numbers-mode\" data-highlighter=\"shiki\" data-ext=\"csharp\" style=\"--shiki-light:#383A42;--shiki-dark:#abb2bf;--shiki-light-bg:#FAFAFA;--shiki-dark-bg:#282c34\"><pre class=\"shiki shiki-themes one-light one-dark-pro vp-code\"><code class=\"language-csharp\"><span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">public</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> interface</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\"> ISomeInterface</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">&#x3C;</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">T</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">> </span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">where</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\"> T</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\"> : </span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">ISomeInterface</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">&#x3C;</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">T</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">></span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">{</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">    static</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> void</span><span style=\"--shiki-light:#4078F2;--shiki-dark:#61AFEF\"> SomeStaticMethod</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">();</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">}</span></span>\n<span class=\"line\"></span>\n<span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">public</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> void</span><span style=\"--shiki-light:#4078F2;--shiki-dark:#61AFEF\"> Test</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">&#x3C;</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">T</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">>() </span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">where</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\"> T</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\"> : </span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">ISomeInterface</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">&#x3C;</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">T</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">></span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">{</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#E5C07B\">    T</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">.</span><span style=\"--shiki-light:#4078F2;--shiki-dark:#61AFEF\">SomeStaticMethod</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">();</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">}</span></span></code></pre>\n<div class=\"line-numbers\" aria-hidden=\"true\" style=\"counter-reset:line-number 0\"><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div></div></div></li>\n</ol>\n<p>In order to meet these needs, Microsoft and community developers jointly launched the static abstract interface method, and everyone's previous fantasy has now been realized.</p>\n<h2>What is it</h2>\n<p>Static abstract interface method is a new feature in C# 11 (corresponding .NET 7.0). Using the latest version of Visual Studio 2022 and then when NET 7.0 runs, you can taste it fresh.</p>\n<p>It supports declaring the static abstract method in the interface (officially, it supports declaring the static virtual method in the interface, but I still report an error after opening the language preview, and I don't know how to use static virtual for the time being).</p>\n<h2>How to use it</h2>\n<p>For an instance, we can use the feature mentioned above to declare the following interface:</p>\n<div class=\"language-csharp line-numbers-mode\" data-highlighter=\"shiki\" data-ext=\"csharp\" style=\"--shiki-light:#383A42;--shiki-dark:#abb2bf;--shiki-light-bg:#FAFAFA;--shiki-dark-bg:#282c34\"><pre class=\"shiki shiki-themes one-light one-dark-pro vp-code\"><code class=\"language-csharp\"><span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">public</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> interface</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\"> IGetNext</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">&#x3C;</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">T</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">> </span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">where</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\"> T</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\"> : </span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">IGetNext</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">&#x3C;</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">T</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">></span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">{</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">    static</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> abstract</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\"> T</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> operator</span><span style=\"--shiki-light:#4078F2;--shiki-dark:#61AFEF\"> ++</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">(</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">T</span><span style=\"--shiki-light:#383A42;--shiki-dark:#E5C07B\"> other</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">);</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">}</span></span></code></pre>\n<div class=\"line-numbers\" aria-hidden=\"true\" style=\"counter-reset:line-number 0\"><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div></div></div><blockquote>\n<p>Many operators force their parameters to match the type, or implement the type parameters containing the type according to the constraints. So, in this case we constrain <code>T</code> implement <code>IGetNext&lt;T&gt;</code>.</p>\n</blockquote>\n<p>Then, define a structure named <code>RepeatSequence</code> to implement the above interface, which creates a string composed of <code>'A'</code>, and each <code>++</code> operation allows an <code>'A'</code> to be added to the string.</p>\n<div class=\"language-csharp line-numbers-mode\" data-highlighter=\"shiki\" data-ext=\"csharp\" style=\"--shiki-light:#383A42;--shiki-dark:#abb2bf;--shiki-light-bg:#FAFAFA;--shiki-dark-bg:#282c34\"><pre class=\"shiki shiki-themes one-light one-dark-pro vp-code\"><code class=\"language-csharp\"><span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">public</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> struct</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\"> RepeatSequence</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\"> : </span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">IGetNext</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">&#x3C;</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">RepeatSequence</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">></span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">{</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">    private</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> const</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> char</span><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\"> Ch</span><span style=\"--shiki-light:#383A42;--shiki-dark:#56B6C2\"> =</span><span style=\"--shiki-light:#50A14F;--shiki-dark:#98C379\"> 'A'</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">;</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">    public</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> string</span><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\"> Text</span><span style=\"--shiki-light:#383A42;--shiki-dark:#56B6C2\"> =</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\"> new </span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">string</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">(</span><span style=\"--shiki-light:#383A42;--shiki-dark:#E06C75\">Ch</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">, </span><span style=\"--shiki-light:#986801;--shiki-dark:#D19A66\">1</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">);</span></span>\n<span class=\"line\"></span>\n<span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">    public</span><span style=\"--shiki-light:#4078F2;--shiki-dark:#61AFEF\"> RepeatSequence</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">() {}</span></span>\n<span class=\"line\"></span>\n<span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">    public</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> static</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\"> RepeatSequence</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> operator</span><span style=\"--shiki-light:#4078F2;--shiki-dark:#61AFEF\"> ++</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">(</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">RepeatSequence</span><span style=\"--shiki-light:#383A42;--shiki-dark:#E5C07B\"> other</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">)</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">        => </span><span style=\"--shiki-light:#383A42;--shiki-dark:#E06C75\">other</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\"> with { </span><span style=\"--shiki-light:#383A42;--shiki-dark:#E06C75\">Text</span><span style=\"--shiki-light:#383A42;--shiki-dark:#56B6C2\"> =</span><span style=\"--shiki-light:#383A42;--shiki-dark:#E5C07B\"> other</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">.</span><span style=\"--shiki-light:#383A42;--shiki-dark:#E5C07B\">Text</span><span style=\"--shiki-light:#383A42;--shiki-dark:#56B6C2\"> +</span><span style=\"--shiki-light:#383A42;--shiki-dark:#E06C75\"> Ch</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\"> };</span></span>\n<span class=\"line\"></span>\n<span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">    public</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> override</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> string</span><span style=\"--shiki-light:#4078F2;--shiki-dark:#61AFEF\"> ToString</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">() => </span><span style=\"--shiki-light:#383A42;--shiki-dark:#E06C75\">Text</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">;</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">}</span></span></code></pre>\n<div class=\"line-numbers\" aria-hidden=\"true\" style=\"counter-reset:line-number 0\"><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div></div></div><p>Then we can write some testing codes, let them print to screen and we look at the output.</p>\n<div class=\"language-csharp line-numbers-mode\" data-highlighter=\"shiki\" data-ext=\"csharp\" style=\"--shiki-light:#383A42;--shiki-dark:#abb2bf;--shiki-light-bg:#FAFAFA;--shiki-dark-bg:#282c34\"><pre class=\"shiki shiki-themes one-light one-dark-pro vp-code\"><code class=\"language-csharp\"><span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">var</span><span style=\"--shiki-light:#383A42;--shiki-dark:#E06C75\"> str</span><span style=\"--shiki-light:#383A42;--shiki-dark:#56B6C2\"> =</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\"> new </span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">RepeatSequence</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">();</span></span>\n<span class=\"line\"></span>\n<span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">for</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\"> (</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">int</span><span style=\"--shiki-light:#383A42;--shiki-dark:#E06C75\"> i</span><span style=\"--shiki-light:#383A42;--shiki-dark:#56B6C2\"> =</span><span style=\"--shiki-light:#986801;--shiki-dark:#D19A66\"> 0</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">; </span><span style=\"--shiki-light:#383A42;--shiki-dark:#E06C75\">i</span><span style=\"--shiki-light:#383A42;--shiki-dark:#56B6C2\"> &#x3C;</span><span style=\"--shiki-light:#986801;--shiki-dark:#D19A66\"> 10</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">; </span><span style=\"--shiki-light:#383A42;--shiki-dark:#E06C75\">i</span><span style=\"--shiki-light:#383A42;--shiki-dark:#56B6C2\">++</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">)</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#E5C07B\">    Console</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">.</span><span style=\"--shiki-light:#4078F2;--shiki-dark:#61AFEF\">WriteLine</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">(</span><span style=\"--shiki-light:#383A42;--shiki-dark:#E06C75\">str</span><span style=\"--shiki-light:#383A42;--shiki-dark:#56B6C2\">++</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">);</span></span></code></pre>\n<div class=\"line-numbers\" aria-hidden=\"true\" style=\"counter-reset:line-number 0\"><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div></div></div><p>Output:</p>\n<div class=\"language- line-numbers-mode\" data-highlighter=\"shiki\" data-ext style=\"--shiki-light:#383A42;--shiki-dark:#abb2bf;--shiki-light-bg:#FAFAFA;--shiki-dark-bg:#282c34\"><pre class=\"shiki shiki-themes one-light one-dark-pro vp-code\"><code class=\"language-\"><span class=\"line\"><span>A</span></span>\n<span class=\"line\"><span>AA</span></span>\n<span class=\"line\"><span>AAA</span></span>\n<span class=\"line\"><span>AAAA</span></span>\n<span class=\"line\"><span>AAAAA</span></span>\n<span class=\"line\"><span>AAAAAA</span></span>\n<span class=\"line\"><span>AAAAAAA</span></span>\n<span class=\"line\"><span>AAAAAAAA</span></span>\n<span class=\"line\"><span>AAAAAAAAA</span></span>\n<span class=\"line\"><span>AAAAAAAAAA</span></span></code></pre>\n<div class=\"line-numbers\" aria-hidden=\"true\" style=\"counter-reset:line-number 0\"><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div></div></div><h3>Playground</h3>\n<iframe style=\"width: 100%; height: 400px;\" src=\"https://sharplab.io/#v2:EYLgtghglgdgNAFxAJwK7wCYgNQB8ACATAIwCwAUBfgMwAEsCApsgGYQDGjtAkgOKMIAcowAeCADwAVAHy0A7gAtmXSbRA9+Q0RJkUA3hVpHa+YgDZaEYAGcEyDglqqA9gAdmEBM+S1s2ABQuCErIAJQA3BQAvhRUdLZo7I4ASozungDKjACOqIwwnGoaAsJi4qnpCFm5+ZzS+obGrshQAG6eXOzOMLa07AoQPgDCCrQAvLQA5ACCk5HkxiZ0pgAMTtrjtDCMcibEK/4jcLTEEY1G50u0FYyZOXkFjP6htHoxlAvGNHsWN3c1j1obg8Xh8fn8fyq91qXGcwWYoUuizGsjhIXkUGCr3WYk2aOYADpJBtsLQRrQovNLt9nK1mC0MFxVk5nBk7LAAObPcayYliebvCgMZgwCAAGxMhD2AHYGp8jKYLPgACy0ACy0Bg/lWAG0ALqWZAc6yI+WvJHGdo+BKbba7SHVB6cZ5Us2LFjeWj+Bj0TYrcK+8Qnf30PymxYRr7EACc/gSYfmi3eUSAA\"></iframe>\n<h2>Analysing from code aspect</h2>\n<h3>Let's look at IL codes</h3>\n<p>Suppose that we have declared the following interface:</p>\n<div class=\"language-csharp line-numbers-mode\" data-highlighter=\"shiki\" data-ext=\"csharp\" style=\"--shiki-light:#383A42;--shiki-dark:#abb2bf;--shiki-light-bg:#FAFAFA;--shiki-dark-bg:#282c34\"><pre class=\"shiki shiki-themes one-light one-dark-pro vp-code\"><code class=\"language-csharp\"><span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">public</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> interface</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\"> IDeepInSourceCode</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">&#x3C;</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">T</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">> </span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">where</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\"> T</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\"> : </span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">IDeepInSourceCode</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">&#x3C;</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">T</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">></span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">{</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">    void</span><span style=\"--shiki-light:#4078F2;--shiki-dark:#61AFEF\"> SomeMethod</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">();</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">    static</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> abstract</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> void</span><span style=\"--shiki-light:#4078F2;--shiki-dark:#61AFEF\"> SomeStaticAbstractMethod</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">();</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">}</span></span></code></pre>\n<div class=\"line-numbers\" aria-hidden=\"true\" style=\"counter-reset:line-number 0\"><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div></div></div><p>The IL codes of it:</p>\n<div class=\"language-csharp line-numbers-mode\" data-highlighter=\"shiki\" data-ext=\"csharp\" style=\"--shiki-light:#383A42;--shiki-dark:#abb2bf;--shiki-light-bg:#FAFAFA;--shiki-dark-bg:#282c34\"><pre class=\"shiki shiki-themes one-light one-dark-pro vp-code\"><code class=\"language-csharp\"><span class=\"line\"><span style=\"--shiki-light:#A0A1A7;--shiki-light-font-style:italic;--shiki-dark:#7F848E;--shiki-dark-font-style:italic\">// Type: StaticAbstractInterfaceMethods.IDeepInSourceCode`1 </span></span>\n<span class=\"line\"><span style=\"--shiki-light:#A0A1A7;--shiki-light-font-style:italic;--shiki-dark:#7F848E;--shiki-dark-font-style:italic\">// Assembly: StaticAbstractInterfaceMethods, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#A0A1A7;--shiki-light-font-style:italic;--shiki-dark:#7F848E;--shiki-dark-font-style:italic\">// MVID: 27A20D9E-C658-48F7-8AC2-47D46316D62D</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#A0A1A7;--shiki-light-font-style:italic;--shiki-dark:#7F848E;--shiki-dark-font-style:italic\">// Location: F:\\static_abstract\\StaticAbstractInterfaceMethods\\bin\\Debug\\net7.0\\StaticAbstractInterfaceMethods.dll</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#A0A1A7;--shiki-light-font-style:italic;--shiki-dark:#7F848E;--shiki-dark-font-style:italic\">// Sequence point data from f:\\static_abstract\\staticabstractinterfacemethods\\bin\\debug\\net7.0\\staticabstractinterfacemethods.pdb</span></span>\n<span class=\"line\"></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">.</span><span style=\"--shiki-light:#383A42;--shiki-dark:#E5C07B\">class</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> interface</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\"> public</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\"> abstract auto ansi</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">  StaticAbstractInterfaceMethods.IDeepInSourceCode`1&#x3C;(</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">class</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\"> StaticAbstractInterfaceMethods</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">.</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">IDeepInSourceCode</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">`1&#x3C;!0</span><span style=\"--shiki-light:#A0A1A7;--shiki-light-font-style:italic;--shiki-dark:#7F848E;--shiki-dark-font-style:italic\">/*T*/</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">>) T></span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">{</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">  .param constraint [1] </span><span style=\"--shiki-light:#A0A1A7;--shiki-light-font-style:italic;--shiki-dark:#7F848E;--shiki-dark-font-style:italic\">/*T*/</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">, class StaticAbstractInterfaceMethods.IDeepInSourceCode`1&#x3C;!0</span><span style=\"--shiki-light:#A0A1A7;--shiki-light-font-style:italic;--shiki-dark:#7F848E;--shiki-dark-font-style:italic\">/*T*/</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">></span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">    .custom instance void System.Runtime.CompilerServices.NullableAttribute::.ctor([</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">in</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">] unsigned int8)</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">      = (01 00 01 00 00 ) </span><span style=\"--shiki-light:#A0A1A7;--shiki-light-font-style:italic;--shiki-dark:#7F848E;--shiki-dark-font-style:italic\">// .....</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#A0A1A7;--shiki-light-font-style:italic;--shiki-dark:#7F848E;--shiki-dark-font-style:italic\">      // unsigned int8(1) // 0x01</span></span>\n<span class=\"line\"></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">  .method </span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">public</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\"> hidebysig </span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">virtual</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\"> newslot </span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">abstract</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\"> instance</span><span style=\"--shiki-light:#4078F2;--shiki-dark:#ABB2BF\"> void</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#4078F2;--shiki-dark:#61AFEF\">    SomeMethod</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">() cil managed</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">  {</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#A0A1A7;--shiki-light-font-style:italic;--shiki-dark:#7F848E;--shiki-dark-font-style:italic\">    // Can't find a body</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">  } </span><span style=\"--shiki-light:#A0A1A7;--shiki-light-font-style:italic;--shiki-dark:#7F848E;--shiki-dark-font-style:italic\">// end of method IDeepInSourceCode`1::SomeMethod</span></span>\n<span class=\"line\"></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">  .method </span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">public</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\"> hidebysig </span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">static</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> virtual</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> abstract</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\"> void</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">    SomeStaticAbstractMethod() </span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">cil</span><span style=\"--shiki-light:#4078F2;--shiki-dark:#ABB2BF\"> managed</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">  {</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#A0A1A7;--shiki-light-font-style:italic;--shiki-dark:#7F848E;--shiki-dark-font-style:italic\">    // Can't find a body</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">  } </span><span style=\"--shiki-light:#A0A1A7;--shiki-light-font-style:italic;--shiki-dark:#7F848E;--shiki-dark-font-style:italic\">// end of method IDeepInSourceCode`1::SomeStaticAbstractMethod</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">} </span><span style=\"--shiki-light:#A0A1A7;--shiki-light-font-style:italic;--shiki-dark:#7F848E;--shiki-dark-font-style:italic\">// end of class StaticAbstractInterfaceMethods.IDeepInSourceCode`1</span></span></code></pre>\n<div class=\"line-numbers\" aria-hidden=\"true\" style=\"counter-reset:line-number 0\"><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div></div></div><p>It is found that in fact, the difference between the static abstract method and the ordinary interface method is that the <code>newslot</code> and <code>instance</code> keywords become <code>static</code>.</p>\n<p>It means that the specific implementation method of implementing the static abstract interface method must be a method starting with <code>public static</code>.</p>\n<h3>Let's try the inheritance relationship</h3>\n<p>We define two types implementing the interface above:</p>\n<div class=\"language-csharp line-numbers-mode\" data-highlighter=\"shiki\" data-ext=\"csharp\" style=\"--shiki-light:#383A42;--shiki-dark:#abb2bf;--shiki-light-bg:#FAFAFA;--shiki-dark-bg:#282c34\"><pre class=\"shiki shiki-themes one-light one-dark-pro vp-code\"><code class=\"language-csharp\"><span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">public</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> class</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\"> DeepInSourceCodeBase</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\"> : </span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">IDeepInSourceCode</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">&#x3C;</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">DeepInSourceCodeBase</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">></span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">{</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">    public</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> virtual</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> void</span><span style=\"--shiki-light:#4078F2;--shiki-dark:#61AFEF\"> SomeMethod</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">()</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">    {</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#E5C07B\">        Console</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">.</span><span style=\"--shiki-light:#4078F2;--shiki-dark:#61AFEF\">WriteLine</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">(</span><span style=\"--shiki-light:#50A14F;--shiki-dark:#98C379\">\"SomeMethodBase is invoked.\"</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">);</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">    }</span></span>\n<span class=\"line\"></span>\n<span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">    public</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> static</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> void</span><span style=\"--shiki-light:#4078F2;--shiki-dark:#61AFEF\"> SomeStaticAbstractMethod</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">()</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">    {</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#E5C07B\">        Console</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">.</span><span style=\"--shiki-light:#4078F2;--shiki-dark:#61AFEF\">WriteLine</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">(</span><span style=\"--shiki-light:#50A14F;--shiki-dark:#98C379\">\"SomeStaticAbstractMethodBase is invoked.\"</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">);</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">    }</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">}</span></span>\n<span class=\"line\"></span>\n<span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">public</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> class</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\"> DeepInSourceCodeDerived</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\"> : </span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">DeepInSourceCodeBase</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">, </span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">IDeepInSourceCode</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">&#x3C;</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">DeepInSourceCodeDerived</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">></span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">{</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">    public</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> override</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> void</span><span style=\"--shiki-light:#4078F2;--shiki-dark:#61AFEF\"> SomeMethod</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">()</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">    {</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#E5C07B\">        Console</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">.</span><span style=\"--shiki-light:#4078F2;--shiki-dark:#61AFEF\">WriteLine</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">(</span><span style=\"--shiki-light:#50A14F;--shiki-dark:#98C379\">\"SomeMethodDerived is invoked.\"</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">);</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">    }</span></span>\n<span class=\"line\"></span>\n<span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">    public</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> new</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> static</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> void</span><span style=\"--shiki-light:#4078F2;--shiki-dark:#61AFEF\"> SomeStaticAbstractMethod</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">()</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">    {</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#E5C07B\">        Console</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">.</span><span style=\"--shiki-light:#4078F2;--shiki-dark:#61AFEF\">WriteLine</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">(</span><span style=\"--shiki-light:#50A14F;--shiki-dark:#98C379\">\"SomeStaticAbstractMethodDerived is invoked.\"</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">);</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">    }</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">}</span></span></code></pre>\n<div class=\"line-numbers\" aria-hidden=\"true\" style=\"counter-reset:line-number 0\"><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div></div></div><p><code>DeepInSourceCodeBase</code> implementes <code>IDeepInSourceCode&lt;DeepInSourceCodeBase&gt;</code>.</p>\n<p><code>DeepInSourceCodeDerived</code> derives from <code>DeepInSourceCodeBase</code>, overrides <code>SomeMethod</code> method, and covers <code>SomeStaticAbstractMethod</code> method.</p>\n<p>Let's write some testing code:</p>\n<div class=\"language-csharp line-numbers-mode\" data-highlighter=\"shiki\" data-ext=\"csharp\" style=\"--shiki-light:#383A42;--shiki-dark:#abb2bf;--shiki-light-bg:#FAFAFA;--shiki-dark-bg:#282c34\"><pre class=\"shiki shiki-themes one-light one-dark-pro vp-code\"><code class=\"language-csharp\"><span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">public</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> class</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\"> DeepInSourceCodeTester</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">{</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">    public</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> static</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> void</span><span style=\"--shiki-light:#4078F2;--shiki-dark:#61AFEF\"> Test</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">&#x3C;</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">T1</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">, </span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">T2</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">>() </span></span>\n<span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">        where</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\"> T1</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\"> : </span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">IDeepInSourceCode</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">&#x3C;</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">T1</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">>, new()</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">        where</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\"> T2</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\"> : </span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">T1</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">, new()</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">    {</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">        T1</span><span style=\"--shiki-light:#383A42;--shiki-dark:#E06C75\"> t1</span><span style=\"--shiki-light:#383A42;--shiki-dark:#56B6C2\"> =</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\"> new </span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">T1</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">();</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">        T2</span><span style=\"--shiki-light:#383A42;--shiki-dark:#E06C75\"> t2</span><span style=\"--shiki-light:#383A42;--shiki-dark:#56B6C2\"> =</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\"> new </span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">T2</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">();</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#E5C07B\">        t1</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">.</span><span style=\"--shiki-light:#4078F2;--shiki-dark:#61AFEF\">SomeMethod</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">();</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#E5C07B\">        t2</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">.</span><span style=\"--shiki-light:#4078F2;--shiki-dark:#61AFEF\">SomeMethod</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">();</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#E5C07B\">        T1</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">.</span><span style=\"--shiki-light:#4078F2;--shiki-dark:#61AFEF\">SomeStaticAbstractMethod</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">();</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#E5C07B\">        T2</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">.</span><span style=\"--shiki-light:#4078F2;--shiki-dark:#61AFEF\">SomeStaticAbstractMethod</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">();</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">    }</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">}</span></span></code></pre>\n<div class=\"line-numbers\" aria-hidden=\"true\" style=\"counter-reset:line-number 0\"><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div></div></div><p>Add testing codes to <code>Main</code>:</p>\n<div class=\"language-csharp line-numbers-mode\" data-highlighter=\"shiki\" data-ext=\"csharp\" style=\"--shiki-light:#383A42;--shiki-dark:#abb2bf;--shiki-light-bg:#FAFAFA;--shiki-dark-bg:#282c34\"><pre class=\"shiki shiki-themes one-light one-dark-pro vp-code\"><code class=\"language-csharp\"><span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">internal</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> class</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\"> Program</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">{</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">    static</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> void</span><span style=\"--shiki-light:#4078F2;--shiki-dark:#61AFEF\"> Main</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">(</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">string</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">[] </span><span style=\"--shiki-light:#383A42;--shiki-dark:#E5C07B\">args</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">)</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">    {</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#E5C07B\">        DeepInSourceCodeTester</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">.</span><span style=\"--shiki-light:#4078F2;--shiki-dark:#61AFEF\">Test</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">&#x3C;</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">DeepInSourceCodeBase</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">, </span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">DeepInSourceCodeDerived</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">>();</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">    }</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">}</span></span></code></pre>\n<div class=\"line-numbers\" aria-hidden=\"true\" style=\"counter-reset:line-number 0\"><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div></div></div><p>Guess what the result is first?</p>\n<div class=\"language- line-numbers-mode\" data-highlighter=\"shiki\" data-ext style=\"--shiki-light:#383A42;--shiki-dark:#abb2bf;--shiki-light-bg:#FAFAFA;--shiki-dark-bg:#282c34\"><pre class=\"shiki shiki-themes one-light one-dark-pro vp-code\"><code class=\"language-\"><span class=\"line\"><span>SomeMethodBase is invoked.</span></span>\n<span class=\"line\"><span>SomeMethodDerived is invoked.</span></span>\n<span class=\"line\"><span>SomeStaticAbstractMethodBase is invoked.</span></span>\n<span class=\"line\"><span>SomeStaticAbstractMethodDerived is invoked.</span></span></code></pre>\n<div class=\"line-numbers\" aria-hidden=\"true\" style=\"counter-reset:line-number 0\"><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div></div></div><p>Would you guess the result like this?</p>\n<p>Actually, the result is not like this, it's:</p>\n<div class=\"language- line-numbers-mode\" data-highlighter=\"shiki\" data-ext style=\"--shiki-light:#383A42;--shiki-dark:#abb2bf;--shiki-light-bg:#FAFAFA;--shiki-dark-bg:#282c34\"><pre class=\"shiki shiki-themes one-light one-dark-pro vp-code\"><code class=\"language-\"><span class=\"line\"><span>SomeMethodBase is invoked.</span></span>\n<span class=\"line\"><span>SomeMethodDerived is invoked.</span></span>\n<span class=\"line\"><span>SomeStaticAbstractMethodBase is invoked.</span></span>\n<span class=\"line\"><span>SomeStaticAbstractMethodBase is invoked.</span></span></code></pre>\n<div class=\"line-numbers\" aria-hidden=\"true\" style=\"counter-reset:line-number 0\"><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div></div></div><p>Here is the official explanation: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/interface#static-abstract-and-virtual-members</p>\n<p>When we change <code>where T2 : T1, new()</code> to <code>where T2 : IDeepInSourceCode&lt;T2&gt;, new()</code>, the result is what we expect.</p>\n<h3>Playground</h3>\n<iframe style=\"width: 100%; height: 400px;\" src=\"https://sharplab.io/#v2:EYLgtghglgdgNAFxAJwK7wCYgNQB8ACATAIwCwAUBfgMwAEsCApsgGYQDGjtAkgCKOMADtxgBlAPapknAMLiMjADwAVAHy0A7gAtmXZbRA9+QkRKmz5StRQDeFWg9r4ALLQlhGAWUYIt8gBQAlADc9o74xABstBDAAM4IyBwITq7ujKIIEAhQ7ACC8YnJ3r4BIRQAvhRUdES0xsJiktKMcgoAQhBxXIZ8Ao1mLW1KDabNFh1djKq2YQ40tABuUMgIqBAANqlu4h4lfhhBc7R25I7nTsQAnP4AROn78p3d9HH0MIviANaMGAB0t3KZ0cVUowPmtSi23SmWyuQKCSS7AQj0OgWOpwu4WudxhWRy+UKSJRPgOzy4UDesE+P3+gNC4NooNBNSchHq/TG5laln4yCgi1+Bg5Jia3OG5LgRk5YqGlkUo1lE0YfIFvxm5Ex4To4kFyH5Cmhuy8pLKGOO5wiN3uxtRqsFGFe7xpvwBQPOLMZCxgjA0l2iLh2HlhBIRRWRqKOjK1WKtuONIfhROKpow9qFlOd31d9OOzOq5AWdUVg2VykYCWYsy9kIDrnLCRUxClykIqiCtAtjm0uloymIwr6otLPIUTdUUp9GijWIcPeQenZhn7k99M8cMYu/doCAHAF5aFO+8QggzZ332Qh2Qej63T12HLu/g9U/fGecr8/ba/3bP+1/g3xJNERTUo0TPP9CAAjIgMJECIx/CCHHzMEGGYGBNjZS4AHZq0tKFA08aAYH8CIAAYAG0AF0YmQABzOJ0WjB8RQGcZR0YBsmGQP4uIVGURwlKYpRLdjhnTDB21/ZDKgoIA=\"></iframe>\n<h2>How does .NET support <a href=\"https://learn.microsoft.com/en-us/dotnet/standard/generics/math\" target=\"_blank\" rel=\"noopener noreferrer\">Generic Math</a>?</h2>\n<p>In order to support generic math, <strong>. NET 7.0 has reimplemented all the base element types</strong>.</p>\n<p>Take <code>Int32</code> as an example, it now wants to implement more interfaces to perform some generic mathematical operations:</p>\n<div class=\"language-csharp line-numbers-mode\" data-highlighter=\"shiki\" data-ext=\"csharp\" style=\"--shiki-light:#383A42;--shiki-dark:#abb2bf;--shiki-light-bg:#FAFAFA;--shiki-dark-bg:#282c34\"><pre class=\"shiki shiki-themes one-light one-dark-pro vp-code\"><code class=\"language-csharp\"><span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">public</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> readonly</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> struct</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\"> Int32</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">        : </span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">IComparable</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">,</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">          IConvertible</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">,</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">          ISpanFormattable</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">,</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">          IComparable</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">&#x3C;</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">int</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">>,</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">          IEquatable</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">&#x3C;</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">int</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">>,</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">          IBinaryInteger</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">&#x3C;</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">int</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">>,</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">          IMinMaxValue</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">&#x3C;</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">int</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">>,</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">          ISignedNumber</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">&#x3C;</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">int</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">></span></span></code></pre>\n<div class=\"line-numbers\" aria-hidden=\"true\" style=\"counter-reset:line-number 0\"><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div></div></div><p>In addition to some previously implemented interfaces, the following new interfaces have been implemented by <code>Int32</code>:</p>\n<ul>\n<li>\n<p>IBinaryInterger&lt;int&gt;</p>\n<div class=\"language-csharp line-numbers-mode\" data-highlighter=\"shiki\" data-ext=\"csharp\" style=\"--shiki-light:#383A42;--shiki-dark:#abb2bf;--shiki-light-bg:#FAFAFA;--shiki-dark-bg:#282c34\"><pre class=\"shiki shiki-themes one-light one-dark-pro vp-code\"><code class=\"language-csharp\"><span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">public</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> interface</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\"> IBinaryInteger</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">&#x3C;</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">TSelf</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">></span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">        : </span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">IBinaryNumber</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">&#x3C;</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">TSelf</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">>,</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">          IShiftOperators</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">&#x3C;</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">TSelf</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">, </span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">int</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">, </span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">TSelf</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">></span></span>\n<span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">        where</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\"> TSelf</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\"> : </span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">IBinaryInteger</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">&#x3C;</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">TSelf</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">>?</span></span></code></pre>\n<div class=\"line-numbers\" aria-hidden=\"true\" style=\"counter-reset:line-number 0\"><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div></div></div><ul>\n<li>\n<p>IBinaryNumber&lt;int&gt;</p>\n<div class=\"language-csharp line-numbers-mode\" data-highlighter=\"shiki\" data-ext=\"csharp\" style=\"--shiki-light:#383A42;--shiki-dark:#abb2bf;--shiki-light-bg:#FAFAFA;--shiki-dark-bg:#282c34\"><pre class=\"shiki shiki-themes one-light one-dark-pro vp-code\"><code class=\"language-csharp\"><span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">public</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> interface</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\"> IBinaryNumber</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">&#x3C;</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">TSelf</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">></span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">        : </span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">IBitwiseOperators</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">&#x3C;</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">TSelf</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">, </span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">TSelf</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">, </span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">TSelf</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">>,</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">          INumber</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">&#x3C;</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">TSelf</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">></span></span>\n<span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">        where</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\"> TSelf</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\"> : </span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">IBinaryNumber</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">&#x3C;</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">TSelf</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">>?</span></span></code></pre>\n<div class=\"line-numbers\" aria-hidden=\"true\" style=\"counter-reset:line-number 0\"><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div></div></div><ul>\n<li>\n<p>IBitwiseOperators&lt;int, int, int&gt;</p>\n<p>Declared the static abstract methods for overloading four operators: <code>&amp;</code>, <code>|</code>, <code>~</code> and <code>!</code>.</p>\n</li>\n<li>\n<p>INumber&lt;int&gt;</p>\n<div class=\"language-csharp line-numbers-mode\" data-highlighter=\"shiki\" data-ext=\"csharp\" style=\"--shiki-light:#383A42;--shiki-dark:#abb2bf;--shiki-light-bg:#FAFAFA;--shiki-dark-bg:#282c34\"><pre class=\"shiki shiki-themes one-light one-dark-pro vp-code\"><code class=\"language-csharp\"><span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">public</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> interface</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\"> INumber</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">&#x3C;</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">TSelf</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">></span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">        : </span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">IComparable</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">,</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">          IComparable</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">&#x3C;</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">TSelf</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">>,</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">          IComparisonOperators</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">&#x3C;</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">TSelf</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">, </span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">TSelf</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">, </span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">bool</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">>,</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">          IModulusOperators</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">&#x3C;</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">TSelf</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">, </span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">TSelf</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">, </span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">TSelf</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">>,</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">          INumberBase</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">&#x3C;</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">TSelf</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">></span></span>\n<span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">        where</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\"> TSelf</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\"> : </span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">INumber</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">&#x3C;</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">TSelf</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">>?</span></span></code></pre>\n<div class=\"line-numbers\" aria-hidden=\"true\" style=\"counter-reset:line-number 0\"><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div></div></div><ul>\n<li>\n<p>IComparisonOperators&lt;int, int, int&gt;</p>\n<p>Declared the static abstract methods for overloading four operators: <code>&gt;</code>, <code>&lt;</code>, <code>&gt;=</code> and <code>&lt;=</code>.</p>\n</li>\n<li>\n<p>IModulusOperators&lt;int, int, int&gt;</p>\n<p>Declared the static abstract method for overloading the operator: <code>%</code>.</p>\n</li>\n<li>\n<p>INumberBase&lt;int&gt;</p>\n<div class=\"language-csharp line-numbers-mode\" data-highlighter=\"shiki\" data-ext=\"csharp\" style=\"--shiki-light:#383A42;--shiki-dark:#abb2bf;--shiki-light-bg:#FAFAFA;--shiki-dark-bg:#282c34\"><pre class=\"shiki shiki-themes one-light one-dark-pro vp-code\"><code class=\"language-csharp\"><span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">public</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> interface</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\"> INumberBase</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">&#x3C;</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">TSelf</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">></span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">        : </span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">IAdditionOperators</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">&#x3C;</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">TSelf</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">, </span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">TSelf</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">, </span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">TSelf</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">>,</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">          IAdditiveIdentity</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">&#x3C;</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">TSelf</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">, </span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">TSelf</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">>,</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">          IDecrementOperators</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">&#x3C;</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">TSelf</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">>,</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">          IDivisionOperators</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">&#x3C;</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">TSelf</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">, </span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">TSelf</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">, </span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">TSelf</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">>,</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">          IEquatable</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">&#x3C;</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">TSelf</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">>,</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">          IEqualityOperators</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">&#x3C;</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">TSelf</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">, </span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">TSelf</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">, </span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">bool</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">>,</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">          IIncrementOperators</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">&#x3C;</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">TSelf</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">>,</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">          IMultiplicativeIdentity</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">&#x3C;</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">TSelf</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">, </span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">TSelf</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">>,</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">          IMultiplyOperators</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">&#x3C;</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">TSelf</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">, </span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">TSelf</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">, </span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">TSelf</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">>,</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">          ISpanFormattable</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">,</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">          ISpanParsable</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">&#x3C;</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">TSelf</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">>,</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">          ISubtractionOperators</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">&#x3C;</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">TSelf</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">, </span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">TSelf</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">, </span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">TSelf</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">>,</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">          IUnaryPlusOperators</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">&#x3C;</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">TSelf</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">, </span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">TSelf</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">>,</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">          IUnaryNegationOperators</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">&#x3C;</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">TSelf</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">, </span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">TSelf</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">></span></span>\n<span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">        where</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\"> TSelf</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\"> : </span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">INumberBase</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">&#x3C;</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">TSelf</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">>?</span></span></code></pre>\n<div class=\"line-numbers\" aria-hidden=\"true\" style=\"counter-reset:line-number 0\"><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div></div></div><p>Mainly declared the static abstract methods for overloading four operators: <code>+</code>, <code>-</code>, <code>*</code>, <code>/</code>.</p>\n</li>\n</ul>\n</li>\n</ul>\n</li>\n<li>\n<p>IShiftOperators&lt;int, int, int&gt;</p>\n<p>Declared the static abstract methods for overloading three operators: <code>&lt;&lt;</code>, <code>&gt;&gt;</code>, and <code>&gt;&gt;&gt;</code>.</p>\n</li>\n</ul>\n</li>\n<li>\n<p>IMinMaxValue&lt;int&gt;</p>\n<p>Declared two static abstract properties: <code>MinValue</code> and <code>MaxValue</code>.</p>\n</li>\n<li>\n<p>ISignedNumber&lt;int&gt;</p>\n<p>Declared a static abstract property: <code>NegativeOne</code>.</p>\n</li>\n</ul>\n<p>In this way, <code>Int32</code> can be used as a generic parameter for generic math.</p>\n<p>In addition to <code>Int32</code>, other element types such as <code>Single</code>, <code>Double</code> and <code>Byte</code> also implement many of these interfaces for generic mathematical operations.</p>\n<p>Take a simple example:</p>\n<div class=\"language-csharp line-numbers-mode\" data-highlighter=\"shiki\" data-ext=\"csharp\" style=\"--shiki-light:#383A42;--shiki-dark:#abb2bf;--shiki-light-bg:#FAFAFA;--shiki-dark-bg:#282c34\"><pre class=\"shiki shiki-themes one-light one-dark-pro vp-code\"><code class=\"language-csharp\"><span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">public</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> static</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> void</span><span style=\"--shiki-light:#4078F2;--shiki-dark:#61AFEF\"> MultiplyAndSub</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">&#x3C;</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">T</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">>(</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">T</span><span style=\"--shiki-light:#383A42;--shiki-dark:#E5C07B\"> t1</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">, </span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">T</span><span style=\"--shiki-light:#383A42;--shiki-dark:#E5C07B\"> t2</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">, </span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">T</span><span style=\"--shiki-light:#383A42;--shiki-dark:#E5C07B\"> t3</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">)</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">    where</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\"> T</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\"> : </span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">IMultiplyOperators</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">&#x3C;</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">T</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">, </span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">T</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">, </span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">T</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">>, </span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">ISubtractionOperators</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">&#x3C;</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">T</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">, </span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">T</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">, </span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">T</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">></span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">{</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#E5C07B\">    Console</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">.</span><span style=\"--shiki-light:#4078F2;--shiki-dark:#61AFEF\">WriteLine</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">(</span><span style=\"--shiki-light:#383A42;--shiki-dark:#E06C75\">t1</span><span style=\"--shiki-light:#383A42;--shiki-dark:#56B6C2\"> *</span><span style=\"--shiki-light:#383A42;--shiki-dark:#E06C75\"> t2</span><span style=\"--shiki-light:#383A42;--shiki-dark:#56B6C2\"> -</span><span style=\"--shiki-light:#383A42;--shiki-dark:#E06C75\"> t3</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">);</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">}</span></span></code></pre>\n<div class=\"line-numbers\" aria-hidden=\"true\" style=\"counter-reset:line-number 0\"><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div></div></div><p>The above method constraints <code>T</code> support multiplication and subtraction operations.</p>\n<p>The above method can be called like this:</p>\n<div class=\"language-csharp line-numbers-mode\" data-highlighter=\"shiki\" data-ext=\"csharp\" style=\"--shiki-light:#383A42;--shiki-dark:#abb2bf;--shiki-light-bg:#FAFAFA;--shiki-dark-bg:#282c34\"><pre class=\"shiki shiki-themes one-light one-dark-pro vp-code\"><code class=\"language-csharp\"><span class=\"line\"><span style=\"--shiki-light:#4078F2;--shiki-dark:#61AFEF\">MultiplyAndSub</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">(</span><span style=\"--shiki-light:#986801;--shiki-dark:#D19A66\">1</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">, </span><span style=\"--shiki-light:#986801;--shiki-dark:#D19A66\">2</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">, </span><span style=\"--shiki-light:#986801;--shiki-dark:#D19A66\">3</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">);</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#4078F2;--shiki-dark:#61AFEF\">MultiplyAndSub</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">(</span><span style=\"--shiki-light:#986801;--shiki-dark:#D19A66\">0.1f</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">, </span><span style=\"--shiki-light:#986801;--shiki-dark:#D19A66\">0.2f</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">, </span><span style=\"--shiki-light:#986801;--shiki-dark:#D19A66\">0.3f</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">);</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#4078F2;--shiki-dark:#61AFEF\">MultiplyAndSub</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">(</span><span style=\"--shiki-light:#986801;--shiki-dark:#D19A66\">0.1d</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">, </span><span style=\"--shiki-light:#986801;--shiki-dark:#D19A66\">0.2d</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">, </span><span style=\"--shiki-light:#986801;--shiki-dark:#D19A66\">0.3d</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">);</span></span></code></pre>\n<div class=\"line-numbers\" aria-hidden=\"true\" style=\"counter-reset:line-number 0\"><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div></div></div><p>Of course, we can also define a type by ourselves, and then implement the interface related to multiplication and subtraction:</p>\n<div class=\"language-csharp line-numbers-mode\" data-highlighter=\"shiki\" data-ext=\"csharp\" style=\"--shiki-light:#383A42;--shiki-dark:#abb2bf;--shiki-light-bg:#FAFAFA;--shiki-dark-bg:#282c34\"><pre class=\"shiki shiki-themes one-light one-dark-pro vp-code\"><code class=\"language-csharp\"><span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">public</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> struct</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\"> MultiplyAndSubCustomStruct</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\"> : </span></span>\n<span class=\"line\"><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">    IMultiplyOperators</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">&#x3C;</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">MultiplyAndSubCustomStruct</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">, </span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">MultiplyAndSubCustomStruct</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">, </span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">MultiplyAndSubCustomStruct</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">>,</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">    ISubtractionOperators</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">&#x3C;</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">MultiplyAndSubCustomStruct</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">, </span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">MultiplyAndSubCustomStruct</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">, </span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">MultiplyAndSubCustomStruct</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">></span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">{</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">    public</span><span style=\"--shiki-light:#4078F2;--shiki-dark:#61AFEF\"> MultiplyAndSubCustomStruct</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">(</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">int</span><span style=\"--shiki-light:#383A42;--shiki-dark:#E5C07B\"> value</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">)</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">    {</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#E06C75\">        Value</span><span style=\"--shiki-light:#383A42;--shiki-dark:#56B6C2\"> =</span><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\"> value</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">;</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">    }</span></span>\n<span class=\"line\"></span>\n<span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">    public</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> int</span><span style=\"--shiki-light:#E45649;--shiki-dark:#E06C75\"> Value</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">;</span></span>\n<span class=\"line\"></span>\n<span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">    public</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> static</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\"> MultiplyAndSubCustomStruct</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> operator</span><span style=\"--shiki-light:#4078F2;--shiki-dark:#61AFEF\"> *</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">(</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">MultiplyAndSubCustomStruct</span><span style=\"--shiki-light:#383A42;--shiki-dark:#E5C07B\"> left</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">, </span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">MultiplyAndSubCustomStruct</span><span style=\"--shiki-light:#383A42;--shiki-dark:#E5C07B\"> right</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">)</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">    {</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">        return</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\"> new </span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">MultiplyAndSubCustomStruct</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">(</span><span style=\"--shiki-light:#383A42;--shiki-dark:#E5C07B\">left</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">.</span><span style=\"--shiki-light:#383A42;--shiki-dark:#E5C07B\">Value</span><span style=\"--shiki-light:#383A42;--shiki-dark:#56B6C2\"> *</span><span style=\"--shiki-light:#383A42;--shiki-dark:#E5C07B\"> right</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">.</span><span style=\"--shiki-light:#383A42;--shiki-dark:#E5C07B\">Value</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">);</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">    }</span></span>\n<span class=\"line\"></span>\n<span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">    public</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> static</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\"> MultiplyAndSubCustomStruct</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> operator</span><span style=\"--shiki-light:#4078F2;--shiki-dark:#61AFEF\"> -</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">(</span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">MultiplyAndSubCustomStruct</span><span style=\"--shiki-light:#383A42;--shiki-dark:#E5C07B\"> left</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">, </span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">MultiplyAndSubCustomStruct</span><span style=\"--shiki-light:#383A42;--shiki-dark:#E5C07B\"> right</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">)</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">    {</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">        return</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\"> new </span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">MultiplyAndSubCustomStruct</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">(</span><span style=\"--shiki-light:#383A42;--shiki-dark:#E5C07B\">left</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">.</span><span style=\"--shiki-light:#383A42;--shiki-dark:#E5C07B\">Value</span><span style=\"--shiki-light:#383A42;--shiki-dark:#56B6C2\"> -</span><span style=\"--shiki-light:#383A42;--shiki-dark:#E5C07B\"> right</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">.</span><span style=\"--shiki-light:#383A42;--shiki-dark:#E5C07B\">Value</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">);</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">    }</span></span>\n<span class=\"line\"></span>\n<span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">    public</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\"> string</span><span style=\"--shiki-light:#4078F2;--shiki-dark:#61AFEF\"> ToString</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">(</span><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">string</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">? </span><span style=\"--shiki-light:#383A42;--shiki-dark:#E5C07B\">format</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">, </span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">IFormatProvider</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">? </span><span style=\"--shiki-light:#383A42;--shiki-dark:#E5C07B\">formatProvider</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">)</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">    {</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#A626A4;--shiki-dark:#C678DD\">        return</span><span style=\"--shiki-light:#383A42;--shiki-dark:#E5C07B\"> Value</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">.</span><span style=\"--shiki-light:#4078F2;--shiki-dark:#61AFEF\">ToString</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">(</span><span style=\"--shiki-light:#383A42;--shiki-dark:#E06C75\">format</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">, </span><span style=\"--shiki-light:#383A42;--shiki-dark:#E06C75\">formatProvider</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">);</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">    }</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">}</span></span></code></pre>\n<div class=\"line-numbers\" aria-hidden=\"true\" style=\"counter-reset:line-number 0\"><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div><div class=\"line-number\"></div></div></div><p>You can then call <code>MultiplyAndSub</code>:</p>\n<div class=\"language-csharp line-numbers-mode\" data-highlighter=\"shiki\" data-ext=\"csharp\" style=\"--shiki-light:#383A42;--shiki-dark:#abb2bf;--shiki-light-bg:#FAFAFA;--shiki-dark-bg:#282c34\"><pre class=\"shiki shiki-themes one-light one-dark-pro vp-code\"><code class=\"language-csharp\"><span class=\"line\"><span style=\"--shiki-light:#4078F2;--shiki-dark:#61AFEF\">MultiplyAndSub</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">(new </span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">MultiplyAndSubCustomStruct</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">(</span><span style=\"--shiki-light:#986801;--shiki-dark:#D19A66\">1</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">), new </span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">MultiplyAndSubCustomStruct</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">(</span><span style=\"--shiki-light:#986801;--shiki-dark:#D19A66\">2</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">), new </span><span style=\"--shiki-light:#C18401;--shiki-dark:#E5C07B\">MultiplyAndSubCustomStruct</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">(</span><span style=\"--shiki-light:#986801;--shiki-dark:#D19A66\">3</span><span style=\"--shiki-light:#383A42;--shiki-dark:#ABB2BF\">));</span></span></code></pre>\n<div class=\"line-numbers\" aria-hidden=\"true\" style=\"counter-reset:line-number 0\"><div class=\"line-number\"></div></div></div><p>The result is <code>-1</code>, which meets expectations.</p>\n",
      "date_published": "2022-11-30T00:00:00.000Z",
      "date_modified": "2022-12-17T14:58:15.000Z",
      "authors": [
        {
          "name": "Lazy_V"
        }
      ],
      "tags": [
        "Programming Languages"
      ]
    },
    {
      "title": "New Beginning",
      "url": "https://zzxzzk115.github.io/blog/posts/jottings/new-beginning.html",
      "id": "https://zzxzzk115.github.io/blog/posts/jottings/new-beginning.html",
      "summary": "It's time for deploying a new blog!",
      "content_html": "<p>My student discounts of Alibaba Cloud and Tencent Cloud will be used up soon, and the cost of subsequent servers is still not small. To save money, I plan to use GitHub Pages back. This time, I don't intend to use Hexo, but consider using a more powerful static page generator with Vue features: VuePress. I chose Hope as the theme, and then will slowly add some contents. I hope this blog is simpler, refreshing and more suitable for reading.</p>\n<p>To improve my English writing skill, I decide that most subsequent published articles will be written in both English and Chinese.</p>\n",
      "date_published": "2022-11-27T00:00:00.000Z",
      "date_modified": "2025-02-12T00:00:16.000Z",
      "authors": [
        {
          "name": "Lazy_V"
        }
      ],
      "tags": [
        "Jottings"
      ]
    },
    {
      "title": "Implement automatically increase ids in MongoDB",
      "url": "https://zzxzzk115.github.io/blog/posts/backend/mongodb/auto-increment-id-in-mongodb.html",
      "id": "https://zzxzzk115.github.io/blog/posts/backend/mongodb/auto-increment-id-in-mongodb.html",
      "summary": "In MongoDB, every documents have an object id (Bson ID). But sometimes we need ids that can automatically increase when creating a new model. And the id should be an integer sta...",
      "content_html": "<p>In MongoDB, every documents have an object id (Bson ID). But sometimes we need ids that can automatically increase when creating a new model. And the id should be an integer starts from 1. How to deal with the problem?</p>\n<!-- more -->\n<h2>How to solve the problem</h2>\n<p>To solve the problem, we have to create a new collection named AutoIncrementIdCollection, in which we insert some models (AutoIncrementIdModel) that have two fields:</p>\n<ol>\n<li>CollectionName --&gt; The name of a collection.</li>\n<li>Sequence --&gt; The current sequence of a collection. The default value of it should be 0.</li>\n</ol>\n<p>Everytime before inserting a new indexed model M to a collection C, we find a AutoIncrementIdModel whose CollectionName is C, and we increase its Sequence by one, then use that sequence to create M (M's id field be initialized by the sequence) and insert it to C.</p>\n",
      "date_published": "2022-11-27T00:00:00.000Z",
      "date_modified": "2022-12-17T14:58:15.000Z",
      "authors": [
        {
          "name": "Lazy_V"
        }
      ],
      "tags": [
        "Backend"
      ]
    }
  ]
}