Wednesday, September 18, 2013

How can i make and calculate a new List that will have the items minus the number of items from another List ?

Another way:



using System;
using System.Collections.Generic;

namespace CSharp
{
class Program
{

static void Main()
{
//Generate for List
List<string> file = new List<string>();
for (int i = 0; i < 61; i++)
{
file.Add(string.Format("file{0:000000}", i));
}

//Copy a copy list
List<string> copyfile = new List<string>(file);

//Generate for List1
List<string> file1 = new List<string>();
for (int i = 0; i < 9; i++)
{
file1.Add(string.Format("test{0:000000}", i));
}

//Check file
for (int i = 0; i < file.Count; i++)
{
if(file1.FindIndex(s=>s.Substring(4)==file[i].Substring(4))>=0)
{
//Do delete
file.RemoveAt(i);
--i;
}
}

//Output
foreach (var item in file)
{
Console.WriteLine(item);
}
}
}
}



If you think one reply solves your problem, please mark it as An Answer , if you think someone's reply helps you, please mark it as a Proposed Answer



Help by clicking:

Click here to donate your rice to the poor

Click to Donate

Click to feed Dogs & Cats




Found any spamming-senders? Please report at: Spam Report


No comments:

Post a Comment