{ "cells": [ { "cell_type": "markdown", "id": "c6f77059", "metadata": {}, "source": [ "\n", "[comment]: <公用初始化文档>\n" ] }, { "cell_type": "code", "execution_count": 1, "id": "e8bd2ba2", "metadata": { "polyglot_notebook": { "kernelName": "csharp" } }, "outputs": [ { "data": { "text/html": [ "
Installed Packages
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "//公共包引用\n", "#r \"nuget:Newtonsoft.Json\"\n", "\n", "//公用命名空间引用\n", "using Newtonsoft.Json;\n", "using Newtonsoft.Json.Linq;\n", "using Newtonsoft.Json.Schema;\n", "using Newtonsoft.Json.Serialization;\n", "\n", "//公用全局对象:类等\n", "///\n", "/// 初始化文档中的公用学生类\n", "///\n", "public class Student\n", "{\n", " public int Id {get;set;}\n", "\n", " public string Name {get;set;}\n", "\n", " public int Age {get;set;}\n", "}\n", "\n", "//公用方法\n", "public static string StudentToString(Student student)\n", "{\n", " if(student == null) return string.Empty;\n", "\n", " return $\"学生信息 学号:{student.Id}, 姓名:{student.Name}, 年龄:{student.Age}\";\n", "}\n", "\n", "//公用变量\n", "Student SharedStudent = new Student()\n", "{\n", " Id = 1,\n", " Name = \"班长\",\n", " Age = 25\n", "};" ] } ], "metadata": { "kernelspec": { "display_name": ".NET (C#)", "language": "C#", "name": ".net-csharp" }, "polyglot_notebook": { "kernelInfo": { "defaultKernelName": "csharp", "items": [ { "aliases": [], "languageName": "csharp", "name": "csharp" } ] } } }, "nbformat": 4, "nbformat_minor": 5 }