Update dotnet for api c#

Eugenia Ernesto Muaca 21 Reputation points
2021-07-05T12:38:56.76+00:00

Hello everybody,

I'm a new c# programmer. I want have some information about c#. I have a c# api running on dotnet core 2.
I want update the dotnet version to version 3 or 5. Which version do you recommend and why?

Developer technologies C#
0 comments No comments
{count} votes

Accepted answer
  1. Karen Payne MVP 35,586 Reputation points Volunteer Moderator
    2021-07-05T13:49:06.627+00:00

    Moving to .NET Core 5, C#9 provides many benefits found here for .NET Core 5 over former versions of .NET Core and new features for C# 9 found here.

    Also, .NET Core 3 has reached end of life.

    Some new features

    Ranges

    var list = new List<string> {"abc", "def", "ghi"};  
    Range range = new Range(0, ^1);  
    List<string> subList1 = list.GetRange(range);  
    List<string> subList = list.GetRange(0..1);  
      
      
    Console.WriteLine($"{string.Join(",", subList1.ToArray())}");  
    Console.WriteLine($"{string.Join(",", subList.ToArray())}");  
    

    Switches

    /// <summary>  
    /// Any version of C#  
    /// </summary>  
    /// <param name="caseSwitch"></param>  
    private static void Conventional1(int caseSwitch)  
    {  
      
        switch (caseSwitch)  
        {  
            case 1:  
                Operations.Case1();  
                break;  
            case 2:  
                Operations.Case2();  
                break;  
            default:  
                throw new ArgumentOutOfRangeException("Dude, unknown int for case");  
        }  
          
    }  
      
    /// <summary>  
    /// C# 8, 9  
    /// </summary>  
    /// <param name="caseSwitch">int</param>  
    private static void ExpressionBodiedMember1_int(int caseSwitch) =>  
        (  
            caseSwitch switch  
            {  
                1 => (Action)Operations.Case1,  
                2 => Operations.Case2,  
                _ => throw new ArgumentOutOfRangeException("Dude, unknown int for case")  
            })  
        ();  
      
    /// <summary>  
    /// C# 8, 9  
    /// </summary>  
    /// <param name="caseSwitch">ApplicationRoles</param>  
    private static void ExpressionBodiedMember1_enum(ApplicationRoles caseSwitch) =>  
        (  
            caseSwitch switch  
            {  
                ApplicationRoles.User => (Action)Operations.Case1,  
                ApplicationRoles.Admin => Operations.Case2,  
                _ => throw new ArgumentOutOfRangeException("Dude, unknown member for case")  
            })  
        ();  
      
    

    Testing for null

    private void Nulls(Countries countries)  
    {  
        if (countries == null)  
        {  
            // any version of C#  
        }  
      
        if (countries is null)  
        {  
            // C#9  
        }  
      
        if (countries is {})  
        {  
            // C#9  
        }  
      
    }  
    

1 additional answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 77,686 Reputation points Volunteer Moderator
    2021-07-06T02:03:48.163+00:00

    This is a bad time to update. Version 5 support ends next February (Feb 2022) and 3.1 (LTS) support ends December 2022. The current 2.1 support ends next month, so your time is limited.

    You should probably upgrade to 3.1 to give yourself a year to upgrade to version 6 after it’s released this November.

    If you don’t care about having support (say you are on 2.0) then you should probably wait until version 6 is released.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.