有一个类:
}
 public class SSEventArgs : EventArgs
    {
        // Fields
        private string _description;
        private string _eventName;
        private string _moduleName;
        private DateTime _time;        // Methods
        public SSEventArgs(string eventName, string moduleName)
        {
            this._eventName = eventName;
            this._moduleName = moduleName;
            DateTime now = DateTime.Now;
            this._time = now;
        }        public SSEventArgs(string eventName, string moduleName, string description)
        {
            this._eventName = eventName;
            this._moduleName = moduleName;
            this._description = description;
            DateTime now = DateTime.Now;
            this._time = now;
        }        public override string ToString()
        {
            string str = null;
            str = string.Format("'{0}' occurred in '{1}'.", this._eventName, this._moduleName);
            if (!string.IsNullOrEmpty(this._description))
            {
                str = str + this._description;
            }
            return str;
        }        // Properties
        public string Description
        {
            get
            {
                return this._description;
            }
            set
            {
                this._description = value;
            }
        }        public string EventName
        {
            get
            {
                return this._eventName;
            }
        }        public string ModuleName
        {
            get
            {
                return this._moduleName;
            }
            set
            {
                this._moduleName = value;
            }
        }        public DateTime Time
        {
            get
            {
                return this._time;
            }
        }    }
    public sealed class SSIOChangeEventArgs : SSEventArgs
    {
        // Fields
        private string _channelName;
        private object _channelValue;        // Methods
        public SSIOChangeEventArgs(string eventName, string moduleName): base(eventName, moduleName)
        {
            ChannelName = _channelName;
            ChannelValue = _channelValue;
        }        public override string ToString()
        {
            return string.Format("'{0}'.IOChannel Name = '{1}'; IOChannel Value = '{2}'.", base.ToString(), this._channelName, this._channelValue);
        }        // Properties
        public string ChannelName
        {
            get
            {
                return this._channelName;
            }
            set
            {
                this._channelName = value;
            }
        }        public object ChannelValue
        {
            get
            {
                return this._channelValue;
            }
            set
            {
                this._channelValue = value;
            }
        }
    }
引用代码是:        private void OnIOChannelChange(string channelName, string channelType, object channelValue)
        {
            EventTest.SSIOChangeEventArgs e = new EventTest.SSIOChangeEventArgs("IOChannelChangeEvent", "IOServerAgent")
            {ChannelName = channelName,ChannelValue = channelValue };
        }为什么这样引用不行呢?

解决方案 »

  1.   

    ChannelName ChannelValue 都是什么,哪里声明了
      

  2.   


        public class SSEventArgs : EventArgs
        {
            // Fields
            private string _description;
            private string _eventName;
            private string _moduleName;
            private DateTime _time;        // Methods
            public SSEventArgs(string eventName, string moduleName)
            {
                _eventName = eventName;
                _moduleName = moduleName;
                DateTime now = DateTime.Now;
                _time = now;
            }        public SSEventArgs(string eventName, string moduleName, string description)
            {
                _eventName = eventName;
                _moduleName = moduleName;
                _description = description;
                DateTime now = DateTime.Now;
                _time = now;
            }        public override string ToString()
            {
                var str = string.Format("'{0}' occurred in '{1}'.", this._eventName, this._moduleName);
                if (!string.IsNullOrEmpty(this._description))
                {
                    str = str + _description;
                }
                return str;
            }        // Properties
            public string Description
            {
                get
                {
                    return _description;
                }
                set
                {
                    _description = value;
                }
            }        public string EventName
            {
                get
                {
                    return _eventName;
                }
            }        public string ModuleName
            {
                get
                {
                    return _moduleName;
                }
                set
                {
                    _moduleName = value;
                }
            }        public DateTime Time
            {
                get
                {
                    return _time;
                }
            }    }
        public sealed class SSIOChangeEventArgs : SSEventArgs
        {
            // Fields
            private string _channelName;
            private object _channelValue;        // Methods
            public SSIOChangeEventArgs(string eventName, string moduleName)
                : base(eventName, moduleName)
            {
                ChannelName = _channelName;
                ChannelValue = _channelValue;
            }        public override string ToString()
            {
                return string.Format("'{0}'.IOChannel Name = '{1}'; IOChannel Value = '{2}'.", base.ToString(), this._channelName, this._channelValue);
            }        // Properties
            public string ChannelName
            {
                get
                {
                    return _channelName;
                }
                set
                {
                    _channelName = value;
                }
            }        public object ChannelValue
            {
                get
                {
                    return _channelValue;
                }
                set
                {
                    _channelValue = value;
                }
            }
        }        private void OnIOChannelChange(string channelName, string channelType, object channelValue)
            {
                EventTest.SSIOChangeEventArgs e = new EventTest.SSIOChangeEventArgs("IOChannelChangeEvent", "IOServerAgent") { ChannelName = channelName, ChannelValue = channelValue };
            }
      

  3.   

    你的VS版本是多少? 是可以这样使用 但是得看VS版本。
      

  4.   

    这样写是行的
            private void OnIOChannelChange(string channelName, string channelType, object channelValue)
            {
                var e = new SSIOChangeEventArgs("IOChannelChangeEvent", "IOServerAgent") { ChannelName = channelName, ChannelValue = channelValue };
            }
      

  5.   

    这样写是行的
            private void OnIOChannelChange(string channelName, string channelType, object channelValue)
            {
                var e = new SSIOChangeEventArgs("IOChannelChangeEvent", "IOServerAgent") { ChannelName = channelName, ChannelValue = channelValue };
            }