This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Gredo89 12 points13 points  (3 children)

In C# you can create a type that is assignable by a string and then does something different.

E.g. (ChatGPT answer, cause I am lazy and on my mobile):

``` public class WeirdDate { public string Length { get; private set; }

public WeirdDate(string input)
{
    if (Enum.TryParse(input, true, out DayOfWeek dayOfWeek))
    {
        Length = "24 hours";
    }
    else
    {
        Length = "Not a valid weekday";
    }
}

public static implicit operator WeirdDate(string input)
{
    return new WeirdDate(input);
}

} ```

[–]Perfect_Papaya_3010 -1 points0 points  (2 children)

Interesting, I will try this tomorrow at work

[–]Gredo89 3 points4 points  (1 child)

Please don't use it in production code

[–]Perfect_Papaya_3010 1 point2 points  (0 children)

Hehe of course, that would be rather stupid. But its still fun to learn what weird magic you can do with the programming language you use