c# - return a sorted list of int -


i know there multiple other threads on can't wrap head around why it

public int[] practice_5(list<int> items) {     if (items == null)     {         return null;     }     else     {         list<int> items_sorted = items.orderby(p => p).tolist();         return items_sorted;     } } 

so have sorted list of items correctly. i'm assuming no matter workaround try, won't return because can't convert type list<int> int[]?

do have convert variable items_sorted before returning?

try this

public int[] practice_5(list<int> items) {      if (items == null)     {        return null;     }     else     {        return items.orderby(p => p).toarray();     } } 

or if want full refactor, , assuming c# 6.0 or higher.

public int[] practice_5(list<int> items) {     return items?.orderby(p => p).toarray();    } 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -