Skip to content

Example.TimestampedString

IzayoiJiichan edited this page Feb 1, 2025 · 1 revision

Examples

using Izayoi.Data.TimestampedObjects;
using System;

public class Example()
{
    public void Method1()
    {
        TimestampedString ts0 = new();

        // ts0.Timestamp: 0
        // ts0.Value: null

        TimestampedString ts11 = new(default(string?));

        // ts11.Timestamp: (1234567890)
        // ts11.Value: null

        TimestampedString ts12 = new("");

        // ts12.Timestamp: (1234567890)
        // ts12.Value: ""

        TimestampedString ts13 = new("ab");

        // ts13.Timestamp: (1234567890)
        // ts13.Value: "ab"

        long utcNow = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();

        TimestampedString ts21 = new(utcNow, default(string?));

        // ts21.Timestamp: (utcNow)
        // ts21.Value: null

        TimestampedString ts22 = new(utcNow, "");

        // ts22.Timestamp: (utcNow)
        // ts22.Value: ""

        TimestampedString ts23 = new(utcNow, "ab");

        // ts23.Timestamp: (utcNow)
        // ts23.Value: "ab"

        TimestampedString ts24 = new(utcNow, new char[] {'a', 'b', 'c'});

        // ts24.Timestamp: (utcNow)
        // ts24.Value: "abc"

        TimestampedString ts25 = new(utcNow, new char[] {'a', 'b', 'c'}, startIndex: 1, length: 2);

        // ts25.Timestamp: (utcNow)
        // ts25.Value: "bc"
    }

    public void Method2()
    {
        long utcNow = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();

        TimestampedString ts1 = new(utcNow, "abc");
        TimestampedString ts2 = new(utcNow, "abc");

        if (ts1 == ts2)
        {
            // true
        }
    }

    public void Method3()
    {
        long utcNow1 = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();

        TimestampedString ts1 = new(utcNow1, "abc");

        long utcNow2 = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();

        TimestampedString ts2 = new(utcNow2, "abc");

        if (ts1 < ts2)
        {
            // true (ts1.Timestamp < ts2.Timestamp)
        }
    }

    public void Method4()
    {
        long utcNow = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();

        TimestampedString ts1a = new(utcNow, "a");
        TimestampedString ts1b = new(utcNow, "b");

        if (ts1a < ts1b)
        {
            // true ("a" < "b")
        }
    }

    public void Method5()
    {
        long utcNow = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();

        TimestampedString ts1e = new(utcNow, "");
        TimestampedString ts1a = new(utcNow, "a");

        if (ts1e < ts1a)
        {
            // true ("" < "a")
        }
    }

    public void Method6()
    {
        long utcNow = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();

        TimestampedString ts1n = new(utcNow, default(string?));
        TimestampedString ts1e = new(utcNow, "");

        if (ts1n < ts1e)
        {
            // true (null < "")
        }
    }
}

Clone this wiki locally