在询问我的第一个问题并阅读了一些提供的链接之后,我决定从开放源代码vb.net项目中将通信层移植到C#中几个月。我开始很好。现在我确实有一个问题。数据包在当前上下文中不存在
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
namespace Eclipse_5._0
{
class PacketHandler
{
#region Packet Constructors
private delegate void PacketDelegate(int Index, byte[] Data);
private PacketDelegate[] Packet;
public PacketHandler()
{
Packet(Enumerations.ClientPackets.CAddChar) = HandleAddChar;
}
#endregion
#region Packet Methods
public void Handledata(int Index, byte[] Data, int MsgType)
{
ByteBuffer Buff = new ByteBuffer();
Buff.WriteBytes(Data);
if (MsgType < 0)
{
return;
}
if (MsgType >= (int)Enumerations.ClientPackets.CQuit)
{
return;
}
Packet(MsgType).Invoke(Index, Buff.ReadBytes(Buff.Length()));
Buff.Dispose();
}
public void HandleNewAccount(int Index, byte[] Data)
{
//TODO: Add New Player Account File.
}
public void HandleAddChar(int Index, byte[] Data)
{
//TODO: Add New Character to Player Account File.
}
#endregion
}
}
下面这行有错误
Packet(Enumerations.ClientPackets.CAddChar) = HandleAddChar;
任何帮助将是巨大的。
什么是数据包中的错误?另外,编译器错误说的是什么? – Jacob 2011-04-14 21:54:10
约定是使用小写字母来启动变量名称。这样做会使您的代码更易于其他程序员阅读。 – unholysampler 2011-04-14 21:57:30
@unholysampler感谢您的建议。我所知道的一切都是通过YouTube或网络上的教程进行自学。我想我捡到了一些坏习惯。我会尽可能地使用小写字母。 – crzyone9584 2011-04-15 00:36:43