本文介绍了我在委托中得到错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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);
}
}
推荐答案
Quote:
委托bool del(dept d);
delegate bool del(dept d);
to
to
public delegate bool del(dept d);
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();
}
}
}
这篇关于我在委托中得到错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!