草庐IT

delegated-properties

全部标签

c# - 公共(public)静态字符串 MyFunc() 上的 "Expected class, delegate, enum, interface or struct"错误。什么 's an alternative to "字符串”?

当我尝试使用以下静态函数时出现错误。错误:Expectedclass,delegate,enum,interface,orstruct函数(和类):namespaceMyNamespace{publicclassMyClass{//SomeotherstaticmethodsthatuseClasses,delegates,enums,interfaces,orstructspublicstaticstringMyFunc(stringmyVar){stringmyText=myVar;//DosomestuffwithmyTextandmyVarreturnmyText;}}}这导致

c# - 为同一个匿名方法创建两个委托(delegate)实例不相等

考虑以下示例代码:staticvoidMain(string[]args){boolsame=CreateDelegate(1)==CreateDelegate(1);}privatestaticActionCreateDelegate(intx){returndelegate{intz=x;};}您会想象这两个委托(delegate)实例比较起来是相等的,就像它们在使用良好的旧命名方法方法(newAction(MyMethod))时一样。它们比较起来并不相等,因为.NETFramework为每个委托(delegate)实例提供了一个隐藏的闭包实例。由于这两个委托(delegate)实

c# - 我可以颠倒多播委托(delegate)事件的顺序吗?

当您在.NET中订阅事件时,订阅会添加到多播委托(delegate)中。当事件被触发时,委托(delegate)将按照它们被订阅的顺序被调用。我想以某种方式覆盖订阅,以便订阅实际上以反向顺序触发。这可以做到吗?如何做到?我想这样的东西可能是我需要的?:publiceventMyReversedEvent{add{/*magic!*/}remove{/*magic!*/}} 最佳答案 你不需要任何魔法;你只需要反转加法即可。编写delegate1+delegate2会返回一个新委托(delegate),其中包含delegate1中的方

c# - 阻止访问私有(private)成员变量?强制使用公共(public)属性(property)?

我使用的是.NET2.0,因此无法访问自动属性。所以我必须求助于以下编码私有(private)变量和公共(public)属性的方法privatestringm_hello=null;publicstringHello{get{returnm_hello;}set{m_hello=value;}}对于上述private/public成员的包含类的方法,是否有限制访问private变量的方法?我不喜欢我可以使用m_hello或Hello。谢谢。 最佳答案 正如其他人所建议的那样,这应该是一个答案...当面向.NET2.0时,您仍然可以在

c# - 验证错误 : The value 'on' is not valid for <<property name>>

在我的项目中,我有一个模型,您可以在这里看到我模型的一部分:publicclassCheckoutModel{publicboolOtherPlace{get;set;}[RequiredIf("OtherPlace",true,ErrorMessage="")]publicstringOtherPlaceFullName{get;set;}[RequiredIf("OtherPlace",true,ErrorMessage="")]publicintOtherPlaceProvinceId{get;set;}[RequiredIf("OtherPlace",true,ErrorMes

C# - 无法在方法内声明委托(delegate)

我真的在这里空白。我想知道为什么我不能在方法中声明委托(delegate)类型,而是必须在类级别进行声明。namespacedelegate_learning{classProgram{//Worksfinepublicdelegatevoidanon_delgate(inti);staticvoidMain(string[]args){HaveFun();Console.Read();}publicstaticvoidHaveFun(){//Throwsanerror:///delegatevoidanon_delgate(inti);anon_delgatead=delegate(

C#:创建具有 bool 返回类型的多播委托(delegate)

海技术人员,在C#中,我们如何定义接受DateTime对象并返回bool值的多播委托(delegate)。谢谢 最佳答案 publicdelegateboolFoo(DateTimetimestamp);这是使用您描述的签名声明委托(delegate)的方法。所有委托(delegate)都可能是多播的,它们只需要初始化。如:publicboolIsGreaterThanNow(DateTimetimestamp){returnDateTime.Nowtimestamp;}Foof1=IsGreaterThanNow;Foof2=Is

c# - 执行非查询 : Connection property has not been initialized.

下午,所以我已经在这个问题上研究了几个小时,但无法真正克服最后一个障碍。下面是我正在编写的这个程序的代码:usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Diagnostics;usingSystem.Data;usingSystem.Data.SqlClient;usingSystem.Configuration;namespaceTest{classProgram{staticvoidMain(){EventLogalog=newEventLog();

c# - 对于匿名方法,是否存在委托(delegate)语法优于 lambda 表达式的情况?

随着lambda表达式(内联代码)等新功能的出现,是否意味着我们不必再使用委托(delegate)或匿名方法?在我看到的几乎所有示例中,它都是为了使用新语法进行重写。我们仍然必须使用委托(delegate)和lambda表达式的任何地方都行不通吗? 最佳答案 是的,有些地方直接使用匿名委托(delegate)和lambda表达式是行不通的。如果方法采用无类型委托(delegate),则编译器不知道将匿名委托(delegate)/lambda表达式解析为什么,您将收到编译器错误。publicstaticvoidInvoke(Deleg

c# - 如何委托(delegate) telerik GridView 常用方法从每个子页面的父页面调用?

我正在使用TelerikGridview来显示记录列表,我有超过10个页面,我正在使用此gridview并粘贴以下常见事件代码副本(有一些小的变化)在所有这些页面上:protectedvoidPage_Load(objectsender,EventArgse){DisplayRecords()}publicvoidDisplayRecords(){//Gridviewnamesaredifferentondifferentpages.GridView1.DataSource=Fetchingrecordsfromdatabase.GridView1.DataBind();}protec