草庐IT

delegated-properties

全部标签

c# - 应该使用委托(delegate)的一些常见场景是什么?

这个问题在这里已经有了答案:WheredoIusedelegates?[closed](8个答案)关闭9年前。我了解委托(delegate)和事件的工作原理。我也可以想象一些我们应该实现事件的常见场景,但我很难理解在什么情况下应该使用委托(delegate)。谢谢回复用户KVB的帖子:一)Youcanbasicallyusedelegateswhereveryouwouldotherwiseuseaone-methodinterface.我想我有点明白以下几点:C类可以定义方法C.M,它会将接口(interface)IM作为参数。该接口(interface)将定义一个方法IM.A,因此

c# - 如何解决 ReSharper 仅针对显示/值成员的属性的 "unused property"警告?

我已经为一个对象定义了两个属性,“Name”和“ID”,我将其用于具有BindingList数据源的ComboBox的DisplayMember和ValueMember。我最近安装了ReSharper来评估它。ReSharper在对象上向我发出警告,指出这两个属性未被使用。示例代码:BindingListSampleList=newBindingList();//populateSampleListcmbSampleSelector.DisplayMember="Name";cmdSampleSelector.ValueMember="ID";cmbSampleSelector.Dat

c# - 如何在 C# 中为泛型委托(delegate)声明泛型事件

我有一个处理文件上传的用户控件。我定义了一个委托(delegate)如下publicdelegatevoidFileUploadSuccess(Tvalue,FileUploadTypeF)值可以是字符串也可以是字节数组。FileUploadType是一个枚举,它告诉上传的文件类型。现在我已经在用户控件中声明了一个事件来引发它。publiceventFileUploadSuccesssuccessString;//IncaseIwantafilenamepubliceventFileUploadSuccesssuccessStringImage;//IncaseIwantabyte[]

Cucumber extend reports的extent.properties配置

extent.reporter.spark.class=tech.grasshopper.reporters.ReporterAdapter$SparkReportAdapterextent.reporter.json.class=tech.grasshopper.reporters.ReporterAdapter$JsonReportAdapterextent.reporter.pdf.class=tech.grasshopper.reporters.ReporterAdapter$PDFReportAdapterextent.reporter.html.class=tech.grassho

c# - 多线程,Task.Run 错误 'The call is ambiguous between the following methods or properties'

当我尝试构建项目时,显示以下错误消息。Thecallisambiguousbetweenthefollowingmethodsorproperties:'System.Threading.Tasks.Task.Run(System.Action)'and'System.Threading.Tasks.Task.Run(System.Func)'我该如何解决这个问题?publicstaticclassMaintananceManager{privatestaticThreadSafeSocialMediaListPostList=newThreadSafeSocialMediaList(

c# - C# 中是否有可用于属性的委托(delegate)?

给定以下类:classTestClass{publicvoidSetValue(intvalue){Value=value;}publicintValue{get;set;}}我可以TestClasstc=newTestClass();ActionsetAction=tc.SetValue;setAction.Invoke(12);这一切都很好。是否可以使用属性而不是方法来做同样的事情?最好在.net中内置一些东西。 最佳答案 您可以使用反射创建委托(delegate):ActionvalueSetter=(Action)Deleg

c# - 为什么所有委托(delegate)类型都彼此不兼容?

在C#中,所有委托(delegate)类型都彼此不兼容,即使它们具有相同的签名。例如:delegatevoidD1();delegatevoidD2();D1d1=MethodGroup;D2d2=d1;//compiletimeerrorD2d2=newD2(d1);//youneedtodothisinstead这种行为和语言设计决策背后的原因是什么。 最佳答案 InC#alldelegatetypesareincompatiblewithoneanother,eveniftheyhavethesamesignature.Wha

C#:虚函数调用甚至比委托(delegate)调用更快?

我刚好遇到一个代码设计问题。比如说,我有一个"template"方法可以调用一些可能“改变”的函数。一个直观的设计是遵循“模板设计模式”。将更改函数定义为要在子类中覆盖的“虚拟”函数。或者,我可以只使用没有“虚拟”的委托(delegate)函数。委托(delegate)函数被注入(inject),以便它们也可以被定制。最初,我认为第二种“委托(delegate)”方式会比“虚拟”方式更快,但一些代码片段证明它是不正确的。在下面的代码中,第一个DoSomething方法遵循“模板模式”。它调用虚方法IsTokenChar。第二种DoSomthing方法不依赖于虚函数。相反,它有一个传递委

c# - 无法将 lambda 表达式转换为类型 'System.Delegate' 因为它不是委托(delegate)类型?

这个问题在这里已经有了答案:Cannotconvertlambdaexpressiontotype'System.Delegate'(4个答案)关闭9年前。我遇到了一个我似乎无法弄清楚的问题,尽管这是Stackoverflow上的一个标准问题。我正在尝试使用以下代码异步更新我的Bingmap(请注意,这是来自旧的Silverlight项目并且似乎在WPF中不起作用)_map.Dispatcher.BeginInvoke(()=>{_map.Children.Clear();foreach(varprojectedPininpinsToAdd.Where(pin=>PointIsVisi

c# - ASP.NET Core 浏览器链接 `Unable to get property ' 文件'`

在MicrosoftVirtualAcademy类(class)中'IntroductiontoASP.NETCore(formerlyASP.NET5)',视频3,在39:00,他们演示了BrowserLink如何在Edge的F12工具和VisualStudio之间同步代码选择。我还没有看到开箱即用的相同功能。我不知道是否有设置或特殊功能来启用此功能。如果有,它没有在类(class)视频中显示,但视频又是几个月前的了。我以前从未见过此功能。BrowserLink从Edge连接到VisualStudio,在VS中的BrowserLinkDashboard中可以看到。没关系。Edge中有