By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,219 Members | 1,110 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,219 IT Pros & Developers. It's quick & easy.

Can't remove from ArrayList

P: 1
Greetings,

I am having some kind of trouble with some code. I have the following object
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections;
  3.  
  4. namespace ImageServerCleanup
  5. {
  6.     public class DiffList : CollectionBase
  7.     {
  8.         public Diff this[int index]
  9.         {
  10.             get 
  11.             { 
  12.                 return ((Diff)(List[index])); 
  13.             }
  14.             set
  15.             {
  16.                 List[index] = value;
  17.             }
  18.         }
  19.  
  20.         public int Add( Diff value )        
  21.         {            
  22.             return( List.Add( value ) );        
  23.         }        
  24.  
  25.         public int IndexOf( Diff value )    
  26.         {            
  27.             return( List.IndexOf( value ) );        
  28.         }        
  29.  
  30.         public void Insert( int index, Diff value )            
  31.         {            
  32.             List.Insert( index, value );        
  33.         }        
  34.  
  35.         public void Remove( Diff value )          
  36.         {            
  37.             List.Remove( value );        
  38.         }        
  39.  
  40.         public bool Contains( Diff value )          
  41.         {                    
  42.             return( List.Contains( value ) );
  43.         }
  44.  
  45.         public class Diff
  46.         {
  47.             private string _path;
  48.             private string _filename;
  49.  
  50.             public Diff(string path, string filename)
  51.             {
  52.                 this._path = path;
  53.                 this._filename = filename;
  54.             }
  55.  
  56.             public Diff()
  57.             {
  58.  
  59.             }
  60.  
  61.             public string Path
  62.             {
  63.                 get 
  64.                 {
  65.                     return _path;
  66.                 }
  67.                 set
  68.                 {
  69.                     _path = value;
  70.                 }
  71.             }
  72.  
  73.             public string Filename
  74.             {
  75.                 get
  76.                 {
  77.                     return _filename;
  78.                 }
  79.                 set
  80.                 {
  81.                     _filename = value;
  82.                 }
  83.             }
  84.         }
  85.     }
  86. }
  87.  
My code is:
Expand|Select|Wrap|Line Numbers
  1.  
  2. DiffList ArrayA = new DiffList();
  3. for(int row = 0; row < rowCount; row++) 
  4. {
  5.     DiffList.Diff entry = new DiffList.Diff();
  6.     entry.Path = data1.ToString().ToLower();
  7.     entry.Filename = data2.ToString().ToLower(); 
  8.     ArrayA.Add(entry);
  9. }
  10.  
  11. DiffList ArrayB = new DiffList();
  12. for(int row = 0; row < rowCount; row++) 
  13. {
  14.     DiffList.Diff entry = new DiffList.Diff();
  15.     entry.Path = data3.ToString().ToLower();
  16.     entry.Filename = data4.ToString().ToLower(); 
  17.     ArrayB.Add(entry);
  18. }
  19.  
  20. foreach (DiffList.Diff fileToRemove in ArrayA)
  21. {
  22.     ArrayB.Remove(fileToRemove);
  23. }
  24.  
  25.  
What I am doing is filling two two Arrays of this objects and then trying to substract ArrayA from ArrayB, but it doesn't. Anyone knows why?

Thanks
Sep 11 '07 #1
Share this Question
Share on Google+
1 Reply


P: 2
try using a for loop instead of for each.

I think for lists if you use foreach it locks the values so you can't remove or edit it. Same thing happens when you are using gerneric list or data dictionary, if you use foreach it wont let you change the values..but for loop works
Sep 11 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.