methods - C# Sorting - not all code paths return a value -


thanks answers, said before, beginner, maybe i'll try show problem other side. @ beginning wrote working program below, realised task use sealed class , difficult me @ moment.

using system; using system.collections.generic; using system.linq; using system.text;  namespace projekt_1__konsola { sealed class element {     int val;     public element(int e)     {         val = e;     }     public int v     {                 {             return val;         }     } }  class program {     static void ustawieniestylu()     {         console.title = "projekt";         console.backgroundcolor = consolecolor.white;         console.foregroundcolor = consolecolor.black;         console.clear();     }      static void podajliczbę(string komunikat, out int liczba)     {         while (true)         {             console.write(komunikat);             string str = console.readline();             try             {                 liczba = int.parse(str);                 break;             }             catch (formatexception)             {                 console.foregroundcolor = consolecolor.red;                 console.writeline("wprowadzono liczbę w złym formacie");                 console.foregroundcolor = consolecolor.black;             }             catch (overflowexception)             {                 console.foregroundcolor = consolecolor.red;                 console.writeline("wartość jest za duża albo za mała");                 console.foregroundcolor = consolecolor.black;             }             catch (argumentnullexception)             {                 console.foregroundcolor = consolecolor.red;                 console.writeline("napotkano koniec strumienia");                 console.foregroundcolor = consolecolor.black;             }             console.writeline("spróbuj jeszcze raz");         }     }      static void sortuj(int[] tablica)     {         (uint = 1; < tablica.length; i++)         {             uint j = i;             int buf = tablica[j];             while ((j > 0) && (tablica[j - 1] > buf))             {                 tablica[j] = tablica[j - 1];                 j--;             }             tablica[j] = buf;         }     }      static void main(string[] args)     {         ustawieniestylu();          int liczba;         podajliczbę("podaj liczbę elementów posortowania: ", out liczba);         int element, i;         int[] tablica = new int[liczba];         (i = 0; < liczba; i++)             {                 podajliczbę("podaj element [" + + "]: ", out element);                 tablica[i] = element;             }          sortuj(tablica);          console.writeline("posortowane elementy: ");         (i = 0; < liczba; i++)         {             console.writeline("element [{0}] = {1}", i, tablica[i]);         }     } } } 

i have task write program uses exact class written @ beginning. without it easy, it's not, i'm beginner programming , objects. doing wrong?

using system; using system.collections.generic; using system.linq; using system.text;  namespace projekt_1__konsola { sealed class element {     int val;     public element(int e)     {         val = e;     }     public int v     {                 {             return val;         }     } }  class program {     static void ustawieniestylu()     {         console.title = "projekt 1";         console.backgroundcolor = consolecolor.white;         console.foregroundcolor = consolecolor.black;         console.clear();     }      static element[] wczytajdanezkonsoli()     {         while (true)         {             string str = console.readline();             int element;              try             {                 element = int.parse(str);                 break;             }             catch (formatexception)             {                 console.foregroundcolor = consolecolor.red;                 console.writeline("wprowadzono liczbę w złym formacie");                 console.foregroundcolor = consolecolor.black;             }             catch (overflowexception)             {                 console.foregroundcolor = consolecolor.red;                 console.writeline("wartość jest za duża albo za mała, pamiętaj że możesz podać liczby z zakresu 1 4294967295");                 console.foregroundcolor = consolecolor.black;             }             catch (argumentnullexception)             {                 console.foregroundcolor = consolecolor.red;                 console.writeline("napotkano koniec strumienia");                 console.foregroundcolor = consolecolor.black;             }             console.writeline("spróbuj jeszcze raz");         }     }      static void sortowanie(element[] tablica)     {         (uint = 1; < tablica.length; i++)         {             uint j = i;             int buf = tablica[j].v;             while ((j > 0) && (tablica[j - 1].v > buf))             {                 tablica[j].e = tablica[j - 1].v;                 j--;             }             tablica[j].e = buf;         }     }      static void wyświetldane(element[] elementy)     {         console.writeline("posortowane elementy: ");         (int = 0; < elementy.length; i++)         {             console.writeline("element [{0}] = {1}", i, elementy[i].v);         }     }      static void main(string[] args)     {         ustawieniestylu();         element[] elementy = wczytajdanezkonsoli();         sortowanie(elementy);         wyświetldane(elementy);     } } 

}

you need return element[] following method

static element[] wczytajdanezkonsoli() 

note: function wczytajdanezkonsoli() seems tobe doing nothing need create element[] , return it.

you may want add following code create element[] array below:

static element[] wczytajdanezkonsoli() {     element [] myelements = new element[10]; //size depends on equirements     //or can use lis<element> if don't know size     int count = 0;     while (true)     {         string str = console.readline();         int element;          try         {             element = int.parse(str);             myelements[count]=new element(element);             count++;             break;         }       return myelements; 

Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -