public enum MyPacketType { Login, Message, FileTransfer }
private void OnPacketReceived(byte[] data) { PacketType packetType = (PacketType)data[0]; switch (packetType) { case PacketType.Login: HandleLoginPacket(data); break; case PacketType.Message: HandleMessagePacket(data); break; case PacketType.FileTransfer: HandleFileTransferPacket(data); break; default: //Error Handling break; } }In this example, we have a function that handles an incoming packet by determining the packet's type using the PacketType class. We then switch on the packet type and call a function to handle the packet. This function can be part of an application that uses network communication to exchange data with other systems. The packet library used in these examples is not specified, but commonly used packet libraries for C# include Protobuf-Net, Newtonsoft.Json, and MsgPack-Cli.