C#

C# LiteDB でデータベースを作成してレコードをインサートするコード

https://usefuledge.com/how-to-use-portable-nosql-csharp.html
    public static void createLiteDB()
    {
        using (LiteDatabase litedb = new LiteDatabase(@"C:\jwork\@Programming\CoreConsole\DataBase\lite.db"))
        {
            var col = litedb.GetCollection<customer>("customers");

            customer cus = new customer
            {
                name = "John Doe123",
                phones = new string[] { "000-0000", "111-1111" },
                isActive = true,
                additional = "additional data"
            };

            col.Insert(cus);
        }
    }
C#

c# AngleSharpでAタグのhref属性の値を取得するコード

https://usefuledge.com/anglesharp-get-attribute.html
using System;

using AngleSharp;
using AngleSharp.Html.Parser;
using System.Net;
using System.Threading.Tasks;


static void Main(string[] args)
{
    Console.WriteLine("Hello World!");
    Task t =  WebscrapingSample();
}


static async Task WebscrapingSample()
{

    var urlstring = "https://usefuledge.com";

    WebClient wc = new WebClient();
    try
    {
        string htmldocs = wc.DownloadString(urlstring);
        

        var config = Configuration.Default;
        var context = BrowsingContext.New(config);
        var document = await context.OpenAsync(req => req.Content(htmldocs));

        foreach ( var item in document.QuerySelectorAll("a"))
        {
            Console.WriteLine(item.TextContent.Trim() + " " + item.GetAttribute("href"));
        }


    }
    catch (System.Exception)
    {
        throw;
    }
}
Other

JavaScriptで現在の年月日を取得するコード

https://usefuledge.com/getyyyymmdd_hhmmss_js.html
    function getNowYMD(){
        var dt = new Date();
        var y = dt.getFullYear();
        var m = (00 + (dt.getMonth()+1)).slice(-2);
        var d = (00 + dt.getDate()).slice(-2);
        var result = y + m + d;
        return result;
      }

    var dt = new Date();
C#

C#でクラスをJSONに変換するコード

https://usefuledge.com/csharp-json.html
    static void JsonSer()
    {
        Data data = new Data();

        data.id = 1;
        data.name = "john";
        data.dept = "Purchase";

        string jsonStr = JsonSerializer.Serialize(data);
        Console.WriteLine(jsonStr);

    }
An error has occurred. This application may no longer respond until reloaded. Reload 🗙