diff --git a/README.md b/README.md index cc3b89a..a2cd897 100644 --- a/README.md +++ b/README.md @@ -2,4 +2,9 @@ ====================================== 系统学习微软 `Polyglt Notebooks` 多语言笔记本。 + +参考项目: ++ [.Net Interactive](https://github.com/dotnet/interactive) ++ [csharp-notebooks(已归档)](https://github.com/dotnet/csharp-notebooks) ++ b站有相关视频,E文的较多 \ No newline at end of file diff --git a/assets/images/UserInput.png b/assets/images/UserInput.png new file mode 100644 index 0000000..1d28b5a Binary files /dev/null and b/assets/images/UserInput.png differ diff --git a/多语言笔记.1.0.常见问题.ipynb b/多语言笔记.1.0.常见问题.ipynb new file mode 100644 index 0000000..93a4957 --- /dev/null +++ b/多语言笔记.1.0.常见问题.ipynb @@ -0,0 +1,180 @@ +{ + "cells": [ + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "多语言笔记常见问题\n", + "================" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "参考:[官方文档](https://github.com/dotnet/interactive/blob/main/docs/FAQ.md)\n", + "+ 定义和概念\n", + "+ 使用多语言笔记本\n", + "+ 故障与排除" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 定义和概念" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 什么是笔记本?" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 什么是Jupyter Notebook?" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 什么是JupyterLab?" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 什么是前端?" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 使用多语言笔记本" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 故障与排除" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "dotnet_interactive": { + "language": "csharp" + }, + "polyglot_notebook": { + "kernelName": "csharp" + } + }, + "outputs": [], + "source": [ + "var names = new string[]{\"张三\",\"李四\",\"王五\"};" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "dotnet_interactive": { + "language": "csharp" + }, + "polyglot_notebook": { + "kernelName": "csharp" + } + }, + "outputs": [ + { + "data": { + "text/plain": [ + "hello from JavaScript!" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "using Microsoft.DotNet.Interactive;\n", + "using Microsoft.DotNet.Interactive.Commands;\n", + "\n", + "var javascriptCode = \"console.log('hello from JavaScript!')\";\n", + "\n", + "await Kernel.Root.SendAsync(new SubmitCode(javascriptCode, \"javascript\"));" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": ".NET (C#)", + "language": "C#", + "name": ".net-csharp" + }, + "language_info": { + "name": "polyglot-notebook" + }, + "polyglot_notebook": { + "kernelInfo": { + "defaultKernelName": "csharp", + "items": [ + { + "aliases": [], + "name": ".NET" + }, + { + "aliases": [ + "C#", + "c#" + ], + "languageName": "C#", + "name": "csharp" + }, + { + "aliases": [ + "js" + ], + "languageName": "JavaScript", + "name": "javascript" + }, + { + "aliases": [], + "languageName": "KQL", + "name": "kql" + }, + { + "aliases": [ + "frontend" + ], + "name": "vscode" + }, + { + "aliases": [], + "name": "webview" + } + ] + } + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/多语言笔记.100.1.测试.ipynb b/多语言笔记.100.1.测试.ipynb index 5f7a0fd..b68740b 100644 --- a/多语言笔记.100.1.测试.ipynb +++ b/多语言笔记.100.1.测试.ipynb @@ -149,6 +149,47 @@ "let va = await interactive.csharp.getVariable('names');\n", "interactive.csharp" ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 使用用户输入\n", + "\n", + "在 VS Code 顶部,显示一个用户输入框,让用户手动输入内容后,程序单元格可以捕获用户输入内容做相关功能:如下图\n", + "![用户输入](./assets/images/UserInput.png)" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "dotnet_interactive": { + "language": "csharp" + }, + "polyglot_notebook": { + "kernelName": "csharp" + } + }, + "outputs": [ + { + "data": { + "text/plain": [ + "99" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "using Microsoft.DotNet.Interactive;\n", + "\n", + "var input = await Kernel.GetInputAsync(\"请输入一个数字:\");\n", + "\n", + "input.Display();" + ] } ], "metadata": {