Tag: 原始

使用带有Delegate.CreateDelegate的值类型的C#

使用Jon Skeet的文章使reflection飞行和探索代表作为指导,我试图使用Delegate.CreateDelegate方法将属性复制为委托。 这是一个示例类: public class PropertyGetter { public int Prop1 {get;set;} public string Prop2 {get;set;} public object GetPropValue(string propertyName) { var property = GetType().GetProperty(propertyName).GetGetMethod(); propertyDelegate = (Func)Delegate.CreateDelegate(typeof(Func), this, property); return propertyDelegate(); } } 我遇到的问题是当我调用GetPropValue并传入”Prop1″作为参数时,我在调用Delegate.CreateDelegate时收到ArgumentException ,并显示消息”Cannot bind to the target method because its signature or security transparency is not compatible with that of the delegate type.” […]

原始数据类型是c#atomic(线程安全)吗?

例如,multithreading时是否需要锁定bool值?