草庐IT

Delegates

全部标签

C# - 匿名委托(delegate)

像匿名方法一样,我使用“delegate”关键字声明的委托(delegate)是匿名委托(delegate)吗?namespaceTest{publicdelegatevoidMyDelegate();classProgram{staticvoidMain(string[]args){DelegateTesttst=newDelegateTest();tst.Chaining();Console.ReadKey(true);}}classDelegateTest{publiceventMyDelegatedel;publicvoidChaining(){del+=delegate{Co

c# - 我可以访问内部类中的外部类对象吗

这个问题在这里已经有了答案:What'sthebestwayofaccessingfieldintheenclosingclassfromthenestedclass?(9个回答)关闭9年前。我有三个这样的类。classA{publicclassinnerB{//Dosomething}publicclassinnerC{//tryingtoaccessobjBheredirectlyorindirectlyoverhere.//IdonthavetocreateanobjectofinnerB,buttoaccesstheobjectcreatedbyA//i.e.innerBobj

c# - 我可以访问内部类中的外部类对象吗

这个问题在这里已经有了答案:What'sthebestwayofaccessingfieldintheenclosingclassfromthenestedclass?(9个回答)关闭9年前。我有三个这样的类。classA{publicclassinnerB{//Dosomething}publicclassinnerC{//tryingtoaccessobjBheredirectlyorindirectlyoverhere.//IdonthavetocreateanobjectofinnerB,buttoaccesstheobjectcreatedbyA//i.e.innerBobj

c# - 为什么 C# 三元运算符不能与委托(delegate)一起工作?

分支选择函数时,使用三元运算符选择函数可能有意义,但这是不可能的。为什么?publicclassDemo{protectedboolbranch;protectedvoiddemo1(){}protectedvoiddemo2(){}publicActionDoesntWork(){returnbranch?demo1:demo2;}}编译器产生以下错误:Cannotimplicitlyconverttype`methodgroup'to`System.Action' 最佳答案 问题是demo1不是一个简单的表达式,它是一个方法。并

c# - 为什么 C# 三元运算符不能与委托(delegate)一起工作?

分支选择函数时,使用三元运算符选择函数可能有意义,但这是不可能的。为什么?publicclassDemo{protectedboolbranch;protectedvoiddemo1(){}protectedvoiddemo2(){}publicActionDoesntWork(){returnbranch?demo1:demo2;}}编译器产生以下错误:Cannotimplicitlyconverttype`methodgroup'to`System.Action' 最佳答案 问题是demo1不是一个简单的表达式,它是一个方法。并

c# - 为什么不用 .NET 风格的委托(delegate)而不是 Java 中的闭包?

OK,这将是我第三次打死马。但是,这个问题与我前面两个关于闭包/委托(delegate)的问题不同,前两个问题询问委托(delegate)的计划以及闭包的预计规范和实现。这个问题是关于-为什么Java社区努力定义3种不同类型的闭包,而我们可以简单地从我们亲爱的友好邻居-微软那里窃取委托(delegate)锁、库存和桶的整个概念。我很想跳入两个非技术性的结论:Java社区应该保持自豪感,以付出艰辛的努力为代价,不要屈服于借用任何微软的概念或以其他方式证明微软的才华。Delegates是Microsoft的一项专利技术。好吧,除了以上两种可能,Q1。三种(或更多)闭包形式将解决的.NET样

c# - 为什么不用 .NET 风格的委托(delegate)而不是 Java 中的闭包?

OK,这将是我第三次打死马。但是,这个问题与我前面两个关于闭包/委托(delegate)的问题不同,前两个问题询问委托(delegate)的计划以及闭包的预计规范和实现。这个问题是关于-为什么Java社区努力定义3种不同类型的闭包,而我们可以简单地从我们亲爱的友好邻居-微软那里窃取委托(delegate)锁、库存和桶的整个概念。我很想跳入两个非技术性的结论:Java社区应该保持自豪感,以付出艰辛的努力为代价,不要屈服于借用任何微软的概念或以其他方式证明微软的才华。Delegates是Microsoft的一项专利技术。好吧,除了以上两种可能,Q1。三种(或更多)闭包形式将解决的.NET样

c# - 如何将委托(delegate)转换为相同的委托(delegate)?

委托(delegate)的描述有两种:首先,在第三方程序集中:publicdelegatevoidClickMenuItem(objectsender,EventArgse)二、标准:publicdelegatevoidEventHandler(objectsender,EventArgse);我正在尝试编写一个方法,该方法将接收EventHandler类型的参数,并将使用参数ClickMenuItem调用第三方库。如何将ClickMenuItem转换为EventHandler? 最佳答案 幸运的是,这很简单。你可以只写:Click

c# - 如何将委托(delegate)转换为相同的委托(delegate)?

委托(delegate)的描述有两种:首先,在第三方程序集中:publicdelegatevoidClickMenuItem(objectsender,EventArgse)二、标准:publicdelegatevoidEventHandler(objectsender,EventArgse);我正在尝试编写一个方法,该方法将接收EventHandler类型的参数,并将使用参数ClickMenuItem调用第三方库。如何将ClickMenuItem转换为EventHandler? 最佳答案 幸运的是,这很简单。你可以只写:Click

c# - C# : "An object reference is required for the non-static field, method, or property" 错误

我在WPF中编写代码。首先,我编写了一个单独的项目来测试COMport的工作。设备,并且运行良好。接下来我决定将它集成到另一个项目中,但我得到了一个错误。我没有更改代码;我只是将它复制到一个新的代码文件中。此代码运行良好:usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Windows;usingSystem.Windows.Controls;usingSystem.Windows.Data;usingSystem.Windows.Documents;usi