c# - Check if input matches in list -
i have used 2 list, , not sure method use print input. want show months first, let user choose 1 month , show days.
class program { static void main(string[] args) { console.writeline("choose month: "); console.readline(); list<int> list = new list<int> { 31, 28, 31, 30, 31, 30, 31, 31, 30, 30, 30, 31 }; list<string> manad = new list<string> { "januari", "februari", "mars", "april", "maj", "juni", "juli", "augusti", "september", "oktober", "november", "december" }; string inmat; inmat = console.readline(); if (inmat == 31) ; { console.writeline(manad[0] + " " + list[0]); console.readline(); } } } }
with 2 lists better use dictionary code below
using system; using system.collections.generic; using system.linq; using system.text; namespace consoleapplication1 { class program { static void main(string[] args) { console.writeline("choose month: "); console.readline(); dictionary<string,int> dict = new dictionary<string,int>(){ {"januari", 31}, {"februari", 28}, {"mars", 31}, {"april", 30}, {"maj", 31}, {"juni", 30}, {"juli", 31}, {"augusti", 31}, {"september", 30}, {"oktober", 31}, {"november", 30}, {"december", 31} }; int nummberofdays = dict["maj"]; int inmat = int.parse(console.readline()); //get months days = inmat console.writeline(string.join(",", dict.asenumerable().where(x => x.value == inmat).select(y => y.key).toarray())); console.readline(); } } }
Comments
Post a Comment