关于一个类里的 方法 声明,基础问题 谢谢
- C# code
class MSG_READER_EVENT_NOTIFICATION:Message { public PARAM_ReaderEventNotificationData ReaderEventNotificationData; public MSG_READER_EVENT_NOTIFICATION() { base.msgType = 0x3f; base.MSG_ID = MessageID.getNewMessageID(); }// 这里声明了一个与类同名的函数 是啥意思? 里面的两个参数,可以理解为 常量么? public static MSG_READER_EVENT_NOTIFICATION FromBitArray(ref BitArray bit_array, ref int cursor, int length) {// 这里又声明了一个 静态的,类名称类型的 函数 又是啥意思? if (cursor > length) { return null; } new ArrayList(); MSG_READER_EVENT_NOTIFICATION msg_reader_event_notification = new MSG_READER_EVENT_NOTIFICATION();// 这句又是啥意思? int num = 0; cursor += 6; msg_reader_event_notification.msgLen = (uint)((ulong)Util.CalculateVal(ref bit_array, ref cursor, 0x20)); msg_reader_event_notification.msgID = (uint)((ulong)Util.CalculateVal(ref bit_array, ref cursor, 0x20)); msg_reader_event_notification.ReaderEventNotificationData = PARAM_ReaderEventNotificationData.FromBitArray(ref bit_array, ref cursor, length); return msg_reader_event_notification;// 这里是这个函数返回的值了,,是否可以理解为,变量参数呀? }}
[解决办法]
//构造函数
public MSG_READER_EVENT_NOTIFICATION()
//......
//带参构造函数
public static MSG_READER_EVENT_NOTIFICATION FromBitArray(ref BitArray bit_array, ref int cursor, int length)
//......
//产生实例
MSG_READER_EVENT_NOTIFICATION msg_reader_event_notification = new MSG_READER_EVENT_NOTIFICATION();
//......
//MSG_READER_EVENT_NOTIFICATION返回值
return msg_reader_event_notification;
[解决办法]
1.与类同名,且没有返回类型声明,该处为类的构造函数,里面的参数应该是继承自Message类的属性
2.在类中定义一个静态函数,且参数为地址引用
3.实例化对象
4.返回实例化对象
[解决办法]