Search Unity

Unity C# 8 support

Discussion in 'Experimental Scripting Previews' started by Jes28, Apr 18, 2019.

  1. Jes28

    Jes28

    Joined:
    Sep 3, 2012
    Posts:
    459
    Simple question is: Do Unity have plans to support C# 8. If they Do - When? :)
     
  2. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    4,203
    Yes, we do plan to support C# 8. We don't have a release date yet, although I expect our support for it will lag a bit behind Microsoft's.
     
  3. alexzzzz

    alexzzzz

    Joined:
    Nov 20, 2010
    Posts:
    1,410
    I doubt C# 8 itself has a release date yet.
     
  4. Jes28

    Jes28

    Joined:
    Sep 3, 2012
    Posts:
    459
    Ok it is good thanks :)

    Really I have just looking for undated roslyn compiler with support of C#8 so we can enable C#8 through csc.rsp and have benefits of NullableReference warnings in our project :)
     
  5. alexzzzz

    alexzzzz

    Joined:
    Nov 20, 2010
    Posts:
    1,410
    You can play with the project I uploaded a while ago: Would the Roslyn Compiler compile C# 8.0 preview?

    It has Roslyn C# 8.0 Preview compiler integrated. If there is a version of Roslyn newer than 2.11.0.63519, I believe, you can just replace the whole Roslyn folder there with the new version.
     
    SugoiDev likes this.
  6. Jes28

    Jes28

    Joined:
    Sep 3, 2012
    Posts:
    459
  7. Sir-Thorgeir

    Sir-Thorgeir

    Joined:
    Jan 17, 2013
    Posts:
    16
    Any update on the release date for C# 8 support?
     
  8. joncham

    joncham

    Unity Technologies

    Joined:
    Dec 1, 2011
    Posts:
    251
    Likely sometime in the 2020 release cycle.
     
  9. jGate99

    jGate99

    Joined:
    Oct 22, 2013
    Posts:
    953
  10. Jes28

    Jes28

    Joined:
    Sep 3, 2012
    Posts:
    459
    Cool.
    Waiting for Nullables support :)
    I have event prepare command to make nullables warnings to be errors :)
     
  11. OndrejP

    OndrejP

    Joined:
    Jul 19, 2017
    Posts:
    68
    How's it looking with C# 8 in Unity, any chance it will come with 2019.3?
     
  12. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    4,203
    No, as mentioned above, it will be in the 2020 release cycle at the earliest. We don't currently have an ETA, so it might be later.
     
    TextusGames and jGate99 like this.
  13. Jes28

    Jes28

    Joined:
    Sep 3, 2012
    Posts:
    459
    May be you have plans to update C# compiler to latest released so we can adlast turn on some syntactic sugar without true support of new features?
     
    holojotto, alexzzzz, Ramobo and 2 others like this.
  14. Jorhoto

    Jorhoto

    Joined:
    May 7, 2019
    Posts:
    26
    vlads777 and OndrejP like this.
  15. Just_Max_

    Just_Max_

    Joined:
    Nov 13, 2019
    Posts:
    3
    +1, static extensions and default interface implementations are sweet ^_^
     
    OndrejP likes this.
  16. OndrejP

    OndrejP

    Joined:
    Jul 19, 2017
    Posts:
    68
    +1
    I don't think static extensions are part of C# 8.
    But I'm waiting for default interface implementation and some minor things like readonly members and unmanaged constructed types might fit very well into DOTS.
     
  17. CaseyHofland

    CaseyHofland

    Joined:
    Mar 18, 2016
    Posts:
    20
    +5 million
    simple 'using' statements :D
    switch expressions :cool:

    And a personal favorite;
    this:
    Code (CSharp):
    1. int[] array = { 1, 3, 5, 7, 9 };
    2. int i = array[^1]; // returns 9
    3. int[] subArray = array[1..3]; // returns { 3, 5 }
    4. int[] subArray2 = array[^2..]; // returns { 7, 9 }
     
    Last edited: Jan 5, 2020
  18. alexzzzz

    alexzzzz

    Joined:
    Nov 20, 2010
    Posts:
    1,410
    array[1..3] should return 2 elements.
     
  19. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    1,013
    More than c# 8 I need .net standard 2.1 support (fast span). is there a plan for that or will they potentially come together?
     
    goncalo-vasconcelos likes this.
  20. nsxdavid

    nsxdavid

    Joined:
    Apr 6, 2009
    Posts:
    365
    Fast span is pretty important for working with memory in cache friendly ways.
     
    goncalo-vasconcelos likes this.
  21. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    4,203
    We're looking at ways to bring C# 8 and .NET Standard 2.1 (or at least span support) to Unity. Our main concern is that .NET Standard 2.1 is not supported by .NET Framework, so adopting .NET Standard 2.1 would be a breaking change for the Unity ecosystem. In addition, .NET 5 is planned for release near the end of 2020, and we'd like to bring that to Unity users as well.

    We are working though the best way to handle this, but we don't have any updates yet.
     
  22. SugoiDev

    SugoiDev

    Joined:
    Mar 27, 2013
    Posts:
    287
    I hope you guys can figure out a way for us to be able to just drop a new Roslyn whenever it comes out.
    With the old incremental compiler, we could just replace everything (except csc.exe) and it would work with the latest Roslyn from nuget. So, we could update the compiler with a simple nuget.exe install Microsoft.Net.Compilers

    Thanks for keeping us posted!
     
    Jes28 and Peter77 like this.
  23. jGate99

    jGate99

    Joined:
    Oct 22, 2013
    Posts:
    953
    I personally understand the 2.1 limitation, however having C# 8 support will be quite great as it will improve quality of life.
     
    Jorhoto likes this.
  24. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    1,013
    Fast Span only would be good enough for me.
     
    goncalo-vasconcelos and sirxeno like this.
  25. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    4,203
    Indeed C# 8 is separate from .NET Standard 2.1. The main difficulty with C# 8 is that it comes with new requirements for the runtime, namely default interface implementations. But it is possible to move Unity to C# 8 without a breaking change to the ecosystem.

    I think the biggest hurdle here is the C# 8 runtime requirements I mentioned just above. But when we get those implemented in the runtimes properly, this might be something that will work.
     
  26. TheOtherMonarch

    TheOtherMonarch

    Joined:
    Jul 28, 2012
    Posts:
    94
    Honestly I would be more excited if Unity moved from mono to .NET 5
     
  27. CaseyHofland

    CaseyHofland

    Joined:
    Mar 18, 2016
    Posts:
    20
    Whoops, you're right :eek:. Updated my answer immediately.