c# - Storing objects to a list and searching for them -


i want able create series of objects in list , search particular result in list (there may 0, 1 or many hits) , display results in text box.

this have far, can seem display last object entered.

public partial class organiserwindow : form {     public organiserwindow()     {         initializecomponent();     }      list<album> albumlist = new list<album>();      private void createalbum_click(object sender, eventargs e)     {         albumlist.add(new album(albumbox.text, artistbox.text));     }      private void searchalbum_click(object sender, eventargs e)     {         var albumresult = album in albumlist                           album.albumname != null// == albumbox.text                           select new { name = album.albumname, artist = album.artistname };          foreach (var item in albumresult)         {             albumresultbox.text = string.join(environment.newline, item.name + " " + item.artist);         }     } }  public class album {     private string albumname;     private string artistname;      public album(string album, string artist)     {         albumname = album;         artistname = artist;     }      public string albumname     {                  {              return albumname;          }         set          {              albumname = value;          }     }      public string artistname     {                  {              return artistname;          }         set          {              artistname = value;          }     } } 

you forgot use += instead of =

albumresultbox.text += string.join(environment.newline, item.name + " " + item.artist); 

Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -