#!meta {"kernelInfo":{"defaultKernelName":"csharp","items":[{"aliases":[],"name":"csharp"}]}} #!markdown # Polyglot Notebook #!csharp Console.WriteLine("Hello World") #!csharp #r "nuget: System.Net.Http, 4.3.4" using System.Net.Http; var httpClient = new HttpClient(); var response = await httpClient.GetAsync("https://httpbin.org/get"); var content = await response.Content.ReadAsStringAsync(); Console.WriteLine(content); #!csharp public class Person { public string FirstName { get; set; } public string LastName { get; set; } public int Age { get; set; } override public string ToString() { return $"{FirstName} {LastName} is {Age} years old."; } } var person = new Person { FirstName = "john", LastName = "Doe", Age = 25 }; Console.WriteLine(person); person.Display(); #!csharp #!import ../utils/EnumHelper.cs enum DayOfWeek { [Description("星期一")] Monday = 1, [Description("星期二")] Tuesday = 2, [Description("星期三")] Wednesday = 3, [Description("星期四")] Thursday = 4, [Description("星期五")] Friday = 5, [Description("星期六")] Saturday = 6, [Description("星期日")] Sunday = 7 } var desc = EnumHelper.GetDescription(DayOfWeek.Monday); desc.Display(); #!csharp var msg = "Hello Ployglot Notebook!"; #!csharp #!set --name message --value @csharp:msg message.Display(); #!csharp #!share --from csharp message --as newMessage newMessage.Display(); #!csharp #!set --name url --value @input:"Please enter a URL" url.Display(); #!csharp #!set --name age --value 19 age.Display(); #!csharp #!value --name products --mime-type application/json [ {"id": 1, "name": "video game"}, {"id": 2, "name": "book"} ] #!csharp #!share products --from value --as productsJson using System.Text.Json; class Product { public int Id { get; set; } public string Name { get; set; } } var jsonSerializerOptions = new JsonSerializerOptions { PropertyNameCaseInsensitive = true }; var products = JsonSerializer.Deserialize(productsJson, jsonSerializerOptions); products.Display(); #!csharp #!value --from-file ../data/json/test.json --name TestJsonData #!csharp #!share TestJsonData --from value --as jsonData using System.Text.Json; jsonData.Display(); var jsonDoc = JsonDocument.Parse(jsonData); jsonDoc.Display(); var jsonSerializerOptions = new JsonSerializerOptions { PropertyNameCaseInsensitive = true }; var products = JsonSerializer.Deserialize(jsonDoc, jsonSerializerOptions); products.Display(); #!csharp #!time var msg = "Hello Ployglot Notbool!"; Console.Write(msg); #!http GET https://httpbin.org/get #!http POST https://httpbin.org/post