c# - An object of a type convertible to 'int' is required -


this code:

namespace cinemaseats   {public partial class mainform : form     {     private const int numofseats = 60;     private int numofreservedseats = 0;     seat currentseat = new seat();     public mainform()     {         initializecomponent();         initializegui();     }      private void initializegui()     {         radiobutton1.checked = true;         namn.text = string.empty;         pris.text = string.empty;     }     private void button1_click(object sender, eventargs e)     {         **int seatnr = readandvalidateseatnr();**          if (seatnr < 0)         {             messagebox.show("välj ett föremål från listan");             return;         }          if (radiobutton2.checked)             reserveseat(seatnr);         else             cancelseat(seatnr);          updategui(seatnr);     }      public int getnumofseats()     {         return numofseats;     }      **public int readandvalidateseatnr()     {      thelist.items.add(test); //test      return;     }     string test = convert.tostring(2); }** } 

i have converted string "test" int still vs says return value has int? want display 60 "seats in listbox, "seat 1","seat 2" , on. wrote test string see if make work.i'm not sure how getter , setters methods work have figured otu need them here?

in readandvalidateseatnr() function not returning anything:

public int readandvalidateseatnr() {      thelist.items.add(test); //test      return;  //<--------- here nothing being returned } 

my compiler gives same error me :p

enter image description here

change return void if not need return anything:

public void readandvalidateseatnr() {      thelist.items.add(test); //test      //return; redundant statement - not required in case } 

if requirement 1 "seat 1", etc - go enum:

enum my_enum{ seat1=1, seat2= 2};  public int readandvalidateseatnr() {         switch(test)         {              case "seat 1":              thelist.items.add(test); //test              return (int)my_enum.seat1;               case "seat 2":              thelist.items.add(test); //test              return (int)my_enum.seat2;         } } 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -