Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Predicate question
Message
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Titre:
Predicate question
Versions des environnements
Environment:
C# 2.0
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
MS SQL Server
Divers
Thread ID:
01232939
Message ID:
01232939
Vues:
44
Hi All, anyone know of a way to filter datasets using a predicate / delegate ? the code below shows how to do it with a generic list
namespace Predicatefun
{
    class Program
    {
        public List<int> Numbers = new List<int>();
        
        static void Main(string[] args)
        {
            Program p = new Program();
            p.PopulateList();

            List<int> result = p.Numbers.FindAll(new Predicate<int>(p.EvenNumbers));

            result.ForEach(delegate(int i)
            {
                Console.WriteLine("Element number {0} matches predicate criteria", i);
            });

            Console.WriteLine("\nMatches found {0}", result.Count);
         }

        

        private bool EvenNumbers(int i)
        {
            return (i % 2 == 0);
        }

        private void PopulateList()
        {
            for (int i = 1; i <= 100; i++)
            {
                Numbers.Add(i);
            }
        }
    }
}
Regards,
Peter J. Kane



Pete
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform