Note that there are some explanatory texts on larger screens.

plurals
  1. POFind if any element is present in System.Array or not and if exists remove from the original
    primarykey
    data
    text
    <p>I have three System.Array where I store basically phone numbers with 10 characters. The definition is this:</p> <pre><code>private static System.Array objRowAValues; private static System.Array objRowBValues; private static System.Array objRowCValues; </code></pre> <p>I do this because I read a huge Excel file with many cells (around 1 000 000) and process with <code>List&lt;string&gt;</code> is a bit slow. Later in my code I change the System.Array to a <code>List&lt;string&gt;</code> mainly because I fill a ListBox elements. These are the definition for the List</p> <pre><code>private List&lt;string&gt; bd = new List&lt;string&gt;(); private List&lt;string&gt; bl = new List&lt;string&gt;(); private List&lt;string&gt; cm = new List&lt;string&gt;(); </code></pre> <p>I want to check if any values in objRowAValues exists in objRowBValues or in objRowCValues and if exists then remove the existent value, how can I do this? I'm newbiew with C# and this is my first steps.</p> <p><strong>EDIT: here is the code (relevant parts only) of what I'm doing:</strong></p> <pre><code>private List&lt;string&gt; bd = new List&lt;string&gt;(); private static System.Array objRowAValues; private List&lt;string&gt; bl = new List&lt;string&gt;(); private static System.Array objRowBValues; private List&lt;string&gt; cm = new List&lt;string&gt;(); private static System.Array objRowCValues; private List&lt;string&gt; pl = new List&lt;string&gt;(); private static Microsoft.Office.Interop.Excel.Application appExcel; Excel.Application xlApp; Excel.Workbook xlWorkBook; Excel.Worksheet xlWorkSheet; Excel.Range rngARowLast, rngBRowLast, rngCRowLast; long lastACell, lastBCell, lastCCell, fullRow; // this is the main method I use to load all three Excel files and fill System.Array and then convert to List&lt;string&gt; private void btnCargarExcel_Click(object sender, EventArgs e) { if (this.openFileDialog1.ShowDialog() == DialogResult.OK) { if (System.IO.File.Exists(openFileDialog1.FileName)) { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); Thread.Sleep(10000); filePath.Text = openFileDialog1.FileName.ToString(); xlApp = new Microsoft.Office.Interop.Excel.Application(); xlWorkBook = xlApp.Workbooks.Open(openFileDialog1.FileName, 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0); xlWorkSheet = (Excel.Worksheet) xlWorkBook.Worksheets.get_Item(1); fullRow = xlWorkSheet.Rows.Count; lastACell = xlWorkSheet.Cells[fullRow, 1].End(Excel.XlDirection.xlUp).Row; rngARowLast = xlWorkSheet.get_Range("A1", "A" + lastACell); objRowAValues = (System.Array) rngARowLast.Cells.Value; foreach (object elem in objRowAValues) { bd.Add(cleanString(elem.ToString(), 10)); } nrosProcesados.Text = bd.Count().ToString(); listBox1.DataSource = bd; xlWorkBook.Close(true, null, null); xlApp.Quit(); releaseObject(xlWorkSheet); releaseObject(xlWorkBook); releaseObject(xlApp); stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; executiontime.Text = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds/10).ToString(); } else { MessageBox.Show("No se pudo abrir el fichero!"); System.Runtime.InteropServices.Marshal.ReleaseComObject(appExcel); appExcel = null; System.Windows.Forms.Application.Exit(); } } } // This is the method where I clean the existent values from bd (the List where I should remove existent values on bl and existent values on cm private void btnClean_Click(object sender, EventArgs e) { pl = bd; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); Thread.Sleep(10000); pl.RemoveAll(element =&gt; bl.Contains((element))); pl.RemoveAll(element =&gt; cm.Contains((element))); textBox2.Text = pl.Count.ToString(); listBox4.DataSource = pl; stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; textBox6.Text = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10).ToString(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload