Can you use static types as generic arguments in C#? (Joke Video)

Поділитися
Вставка
  • Опубліковано 20 жов 2024

КОМЕНТАРІ • 16

  • @MZZenyl
    @MZZenyl 4 роки тому +9

    Dynamic - The equivalent of telling the compiler to shut up and trust you.

  • @rmcgraw7943
    @rmcgraw7943 4 роки тому +1

    dangerous workaround.

    • @LevelUppp
      @LevelUppp  4 роки тому

      True. it's a compiler bug that will probably never get patched:
      github.com/dotnet/roslyn/blob/master/docs/compilers/CSharp/Static%20Type%20Constraints.md

  • @kostasgkoutis8534
    @kostasgkoutis8534 Місяць тому

    I think this now got fixed

  • @berhalak
    @berhalak 4 роки тому +1

    I wonder why this doesn't compile either.
    using System;

    public class Program
    {
    public static void Main()
    {
    Console.WriteLine(1 / 0);
    }
    }

    • @LevelUppp
      @LevelUppp  4 роки тому +3

      Division by a constant that is Zero.
      But fear not I have a solution for you:
      Console.WriteLine(1 / (dynamic)0);

    • @gnul
      @gnul Рік тому

      @@LevelUppp This even works. But you should wrap it in a method with the [DoesNotReturn] attribute and call it UncancelableDeadlock() xD

  • @clantz
    @clantz 4 роки тому +3

    Dynamic... yuck.

    • @LevelUppp
      @LevelUppp  4 роки тому +1

      Yep :)
      it's a compiler bug that will probably never get patched:
      github.com/dotnet/roslyn/blob/master/docs/compilers/CSharp/Static%20Type%20Constraints.md

    • @rmcgraw7943
      @rmcgraw7943 4 роки тому

      clantz U should use dynamic with the Expando class. Too much fun.

    • @clantz
      @clantz 4 роки тому

      @@rmcgraw7943 I wouldn't call dynamic typing fun..! I shudder at the mere thought of python and js.

    • @rmcgraw7943
      @rmcgraw7943 4 роки тому

      clantz that’s kind of what I was getting at. Fun as in ICK!