c# - Collection<string> cannot accept string values -


I have a Silverlight app. I have Home Page Xml (and its code-back home page. Xaml.cs). button. When I click on the button, Open File Diary opens, then I change the * .txt file from my computer. Convert it to data stream. Then call a completely different class processor COS, where this data stream will be processed and the results will be added to the eclipse. The problem is that my results can not be added to the val collection, the following code is executed:

Home.xaml.cs:

  Zero Button_Click (Object Sender, EventArgs e) {OpenFileDialog opendialog = New OpenFileDialog (); Opendialog.Multiselect = True; Bool? Dialogue = opendialog.ShowDialog (); If (Dialog Result. Haasavalue and Diagnor Result. Val) {Stream Filestream = Op. OpenRaid (); Var processor = new processor (); ICollection & LT; String & gt; Result = Processor. Processing (file stream); }}  

Processor CS

  public class processor {public isolation & lt; String & gt; Process (Stream Stream) {StreamReader Reader = New Streamerdream (Stream); String pattern = @ "set voucher" "([\ w -] +)" ""; While (! Reader.EndOfStream) {var match = Regex.Matches (reader.ReadToEnd (), Pattern) .Cast & lt; Match & gt; (). Where (m = & m; m.Success) Select (m = & gt; m group [1]. Value). Undoubtedly (); Foreign (matches match match) {var val = match + environment November; New Collection Back & lt; String & gt; (). Add (Val) ;; // here error}}}  

Such error:

But the 'void' is converted to 'System.Collections.Generic' Can not be changed from ICollection '

You are returning a method instead of a instance object You are getting this exception message besides you are incorrectly processing you

here is a fix

  public class processor {public isolation & lt; String & gt; Process (Stream Stream) {StreamReader Reader = New Streamerdream (Stream); String pattern = @ "set voucher" "([\ w -] +)" ""; Collections & lt; String & gt; MyCollection = New Collection & lt; String & gt; (); While (! Reader.EndOfStream) {var match = Regex.Matches (reader.ReadToEnd (), Pattern) .Cast & lt; Match & gt; (). Where (m = & m; m.Success) Select (m = & gt; m group [1]. Value). Undoubtedly (); Foreign (matches match match) {var val = match + environment November; MyCollection.Add (Val) ;; // here error}} myCollection return; }  

Comments