草庐IT

static_event

全部标签

c# - 跨线程操作无效(How to access WinForm elements from another module events?)

我有一个带有串行端口信号事件的模块serialPort.DataReceived.AddHandler(SerialDataReceivedEventHandler(DataReceived));DataReceived在哪里letDataReceivedab=rxstringProcessData正在调用WinForms方法letProcessData(a,b)=dataProcessor.Invoke(a,b)|>ignore这是privatevoidProcessData(objectsender,EventArgse){byte[]m=Core.ncon.ArrayRead;s

c# - 'Event' 的无效值 - 属性 (XAML Eventsetter)

我正在使用VisualStudio2015社区,但收到以下错误消息:Invalidvaluefor'Event'-Property:Microsoft.VisualStudio.DesignTools.Xaml.LanguageService.Semantics.XmlValue.下面是代码:我试过UIElement.MouseEnter、Mouse.MouseEnter、TextBox.MouseEnter。如果我编译处理程序工作正常,但错误消息仍然存在。有什么建议吗? 最佳答案 这似乎是WPF设计器中的一个错误,正如已经报告的那

c# - UIElement.AddHandler() 与 .Event += 定义

问题的第一部分:这2个事件注册之间有什么区别?_popUp.AddHandler(PreviewMouseLeftButtonDownEvent,newMouseButtonEventHandler(PopUp_PreviewMouseLeftButtonDown));_popUp.PreviewMouseLeftButtonDown+=newMouseButtonEventHandler(_popUp_PreviewMouseLeftButtonDown);问题的第二部分:或最终与popUp.Opened+=PopUp_Opened; 最佳答案

c# - static关键字是什么意思?

我是C#初学者。我发现有两种方法可以编写代码并输出相同的结果。你能解释一下它们之间的区别吗?什么时候使用#1和#2?#1classProgram{staticvoidMain(){Programmin=newProgram();Console.WriteLine(min.isMin(1,2));Console.ReadLine();}intisMin(intvalue1,intvalue2){intMin;returnMin=Math.Min(value1,value2);}}#2classProgram2{staticvoidMain(){Console.WriteLine(isMi

c# - event 关键字的真正作用是什么?

publicdelegatevoidSecondChangedHandler(objectclock,TimeInfoEventArgstimeInformation);publiceventSecondChangedHandlerSecondChanged;我已经基于这个写了一个时钟article.现在,如果我删除event关键字,我会得到相同的结果,那么event到底做了什么? 最佳答案 它的编译方式不同。做到了有人做不到mySecondChangedHandler.SecondChanged=SomeMethod(...);/

c# - Lazy<T> 延迟加载错误 : A field initializer cannot reference the non-static field, 方法或属性

我第一次尝试使用延迟加载来初始化我的类中的进度对象。但是,我收到以下错误:Afieldinitializercannotreferencethenon-staticfield,method,orproperty.privateLazym_progress=newLazy(()=>{longtotalBytes=m_transferManager.TotalSize();returnnewProgress(totalBytes);});在.NET2.0中,我可以执行以下操作,但我更愿意使用更新的方法:privateProgressm_progress;privateProgressPro

c# - public static vs static public - 有区别吗?

sealedclassPI{publicstaticfloatnumber;staticPI(){number=3.141592653F;}staticpublicfloatval(){returnnumber;}}publicstatic和staticpublic有什么区别?它们可以按任何顺序使用吗?我将如何使用staticpublicfloatval()?类一初始化就执行吗? 最佳答案 没有区别。您可以按任一顺序随意指定它们。但是,我发现大多数开发人员倾向于使用publicstatic而不是staticpublic。

C# 4.0 : casting dynamic to static

这是一个分支问题,与我问的另一个问题有关here.我把它分开是因为它真的是一个子问题:我在转换dynamic类型的对象时遇到困难到另一个(已知的)静态类型。我有一个用于执行此操作的IronPython脚本:importclrclr.AddReference("System")fromSystemimport*defGetBclUri():returnUri("http://google.com")请注意,它只是更新BCLSystem.Uri类型并返回它.所以我知道静态类型返回的对象。现在在C#领域,我正在更新脚本托管内容并调用这个getter来返回Uri对象:dynamicuri=sc

c# - 使用 x :Static 指定时忽略 DataTemplate 键

我遇到了DataTemplate键的奇怪行为:当通过x:Type指定DataType,并且通过x:Static引用指定x:Key时,忽略x:Key。我编写了示例应用程序来说明它。XAML资源:C#:publicclassTestDto{}publicstaticclassDataKeys{publicstaticstringTestDtoKey="TestKey";publicstaticstringTestDtoKey2="TestKey2";publicstaticstringTestDtoKey4="TestKey4";}启动应用程序,在调试器中查看this.Resources.

c# - 如何关闭 resharper 中的 "Convert Extension Method to Plain Static"自动重构?

在使用Resharper时,由于某些原因,当我调用扩展方法时,它会自动将其转换为静态方法调用。这就是所谓的ConvertExtensionMethodtoPlainStatic重构。foo.Bar()成为MyStaticExtensions.Bar(foo);具有讽刺意味的是,它随后将此标记为代码异味。我该如何关闭它? 最佳答案 Resharper的IntelliSense中嵌入了此功能。我经常使用Linq-to-sql扩展,所以我禁用了这个功能:Resharper-选项-IntelliSense-启用RadiobuttonVisu