{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Jupyter笔记 简单入门\n",
"=============================="
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"使用 Jupyter NoteBook 形式,优点是代码执行和 Markdown 文档放在同一个文件中,并可以交替显示和分段执行代码。"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## 显式声明使用 C# 语言\n",
"+ csharp\n",
"+ fsharp\n",
"+ pwsh"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"dotnet_interactive": {
"language": "csharp"
},
"polyglot_notebook": {
"kernelName": "csharp"
}
},
"outputs": [],
"source": [
"#!csharp"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## C# 中的引用\n",
"+ 导入程序文件\n",
" > 可以导入多种文件,包括 .cs .csc .fc .js等,语法为` #!import /path/to/file ` \n",
"+ 引用本机 Dll 文件\n",
" > 可以导入本机编译好的dll文件,语法为 `#!import /path/to/file`\n",
"+ 引用 Nuget 包\n",
"+ > 默认包源下,可以导入nuget,当然也可以设置包源,语法为 `#r 包名,可选版本号`"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## C# 中的引用\n",
"+ 导入程序文件\n",
" > 可以导入多种文件,包括 .cs .csc .fc .js等,语法为` #!import /path/to/file ` "
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"dotnet_interactive": {
"language": "csharp"
},
"polyglot_notebook": {
"kernelName": "csharp"
}
},
"outputs": [],
"source": [
"#! import \"../NotebookStudy.ConsoleApp/Persion.cs\""
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"dotnet_interactive": {
"language": "csharp"
},
"polyglot_notebook": {
"kernelName": "csharp"
}
},
"outputs": [
{
"ename": "Error",
"evalue": "(2,13): error CS0246: 未能找到类型或命名空间名“Person”(是否缺少 using 指令或程序集引用?)",
"output_type": "error",
"traceback": [
"(2,13): error CS0246: 未能找到类型或命名空间名“Person”(是否缺少 using 指令或程序集引用?)"
]
}
],
"source": [
"//单纯引用.cs文件,不能直接使用,解决方法待查找\n",
"var p = new Person()\n",
"{\n",
" Id=1,\n",
" Name=\"小张\",\n",
" Address=\"上海无名路1号\",\n",
" Age = 28\n",
"};\n",
"//在NoteBook中,可以格式化显示(Notebook提供) C#对象:使用 display(对象); 如果在代码结尾的话,可以直接写 C#对象。\n",
"display(p);\n",
"\n",
"//代码结尾的话,直接写 对象\n",
"p"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"dotnet_interactive": {
"language": "csharp"
},
"polyglot_notebook": {
"kernelName": "csharp"
}
},
"outputs": [
{
"data": {
"text/html": [
"{ Name = xx, Agx = 33 }
Name xx Agx 33
NotebookStudy.ConsoleApp.Person
Id 2
Name 本山 Address <null>
Age 55