How can show my list and make it searchable? C# -


ok, i'm super new , schoolproject.

the project code program person can store, update , search information.

in program make lists store cloth information (brand, type, color, size) , think information gets stored don't know how access / make search function it.

is code correct? should use strategy?

this list defined(?!)

public class kläddatalist  {     public string märke;     public string typ;     public string färg;     public string storlek;      public kläddatalist(string _märke, string _typ, string _färg, string _storlek)     {         this.märke = _märke;         this.typ = _typ;         this.färg = _färg;         this.storlek = _storlek;     } } 

this wehre string variabels filled through couple of readline() functions.

for exampel:

string _färg = console.readline().toupper(); 

then after i've saved ill make new list, think?:

list<kläddatalist> newkläddatalist = new list<kläddatalist>();             newkläddatalist.add(new kläddatalist(_märke, _typ, _färg, _storlek)); 

i hope can me, thank you!

elements can accessed iterating through collection/list.

foreach( var item in newkläddatalist) {     // access or read item members.     console.writeline(item.märke); } 

when want find element in list, can either use linq

var item = newkläddatalist.firstordefault(e=>e.märke == "searchstring"); //any key identify list item.  if(item != null) {     console.writeline(item.märke); } 

or use find

var item = newkläddatalist.find(e=>e.märke == "searchstring"); 

hope helps!


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -