Farhan Shariff

Farhan Shariff

  • NA
  • 933
  • 241.6k

print ienumerable in text file c#

May 20 2014 3:47 AM

I am matching two string list  (Die_ID_refrence , Die_ID_real)  I want to print all the string Values  present in string list (Reference) and not in (Real) in to a Text file

//---------------------------------------------------------------------------------------
List<String> Die_ID_refrence = new List<String>();   //List stores All Die_ID from Reference sheet
for (int a = 0; a < table5.Rows.Count; a++)
{
Die_ID_refrence.Add(table5.Rows[a]["Die_ID"].ToString());

}

//------------------------------------------------------------------------------------------
List<String> Die_ID_real = new List<String>(); //List stores All Die_ID from Reference sheet
for (int b = 0; b < table3.Rows.Count; b++)
{
Die_ID_real.Add(table3.Rows[b]["Die_ID"].ToString());
}
//---------------------------------------------------------------------------------------
IEnumerable<object> result = Die_ID_refrence.ToArray().Except(Die_ID_real.ToArray()); //Gives you Die_ID in one (Reference) not two (Real)

var collection = result as IEnumerable;
if (collection != null)
{
foreach (var item in collection)
{
 // I want to print the item in to a text file
    File.AppendAllLines(@"C:\Delta Sigma\Log.txt",  ---------------------------);
//how to print this

}

Answers (2)