Click here to Skip to main content
15,900,906 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
C#
public  class dept
    {
        public int deptid { get; set; }
        public string dname { get; set; }
        public int salary { get; set; }
        public int Experience { get; set; }
    }


    public class demp
    {
        static void Main(string[] args)
        {
            List<dept> de = new List<dept>();
            de.Add(new dept() { deptid = 1, dname = "k", salary = 8909, Experience = 2 });
            de.Add(new dept() { deptid = 1, dname = "l", salary = 8909, Experience = 3 });
            de.Add(new dept() { deptid = 1, dname = "m", salary = 8909, Experience = 4 });
            de.Add(new dept() { deptid = 1, dname = "n", salary = 8909, Experience = 5 });

            deptl(de, x => x.Experience > 2);
        }

        public static void deptl(List<dept> ldept,del sk)//getting error in dept1
        {
            foreach (dept item in ldept)
            {
                if (sk(item))
                {
                    Console.WriteLine(item.dname + " IsPromoted");
                    Console.ReadLine();
                }
            }
        }

        delegate bool del(dept d);
    }
}
Posted
Updated 14-Oct-14 20:59pm
v2
Comments
OriginalGriff 15-Oct-14 2:59am    
And?
What error are you getting?
What is it doing that you don't expect, or not doing that you do?
sashkhdr 15-Oct-14 3:06am    
i'm getting error in the staic method dept1

ERROR:
Error 1 Inconsistent accessibility: parameter type 'ClassLibrary1.demp.del' is less accessible than method 'ClassLibrary1.demp.deptl(System.Collections.Generic.List<classlibrary1.dept>, ClassLibrary1.demp.del)'
Pikoh 15-Oct-14 3:09am    
try
public delegate bool del(dept d);
sashkhdr 15-Oct-14 3:12am    
thank you ,Problem Solved

Change from
Quote:
delegate bool del(dept d);
to
public delegate bool del(dept d);
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 15-Oct-14 3:18am    
Sure. However, worth noting: "internal" would suffice.
—SA
instead of delegate we use Lambda expression this is simple way

static void Main()
        { 
List<dept> de = new List<dept>();
            de.Add(new dept() { deptid = 1, dname = "k", salary = 8909, Experience = 2 });
            de.Add(new dept() { deptid = 1, dname = "l", salary = 8909, Experience = 3 });
            de.Add(new dept() { deptid = 1, dname = "m", salary = 8909, Experience = 4 });
            de.Add(new dept() { deptid = 1, dname = "n", salary = 8909, Experience = 5 });

            deptl(de, (x) => { return x.Experience > 2; });


}
 public static void deptl(List<dept> ldept, Func<dept,bool> sk)
        {
            foreach (dept item in ldept)
            {
               
                if ( sk(item))
                {
                    Console.WriteLine(item.dname + " IsPromoted");
                    Console.ReadLine();
                }
            }
        }
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900