嗨,我已经在C#中编写了一个嵌套结构。请看下面的代码片段:如何将值分配给嵌套结构中的主/父结构?
public struct SMB_MESSAGE
{
#region SMB Parameter
public struct SMB_PARAMETERS
{
public byte WordCount;
public ushort[] Words;
}
#endregion
#region SMB Data
public struct SMB_DATA
{
public ushort ByteCount;
public struct Bytes
{
public ushort BufferFormat;
public byte[] Name;
}
}
#endregion
}
现在虽然我赋值给内部结构如下图所示:
SMB_MESSAGE SMBMESSAGE;
SMB_MESSAGE.SMB_PARAMETERS SMBPARAMETER;
SMBPARAMETER.WordCount=12;
SMBPARAMETER.Words=null;
SMB_MESSAGE.SMB_DATA SMBDATA;
SMBDATA.ByteCount=byteCount;
SMB_MESSAGE.SMB_DATA.Bytes bytes;
bytes.BufferFormat=bFormat;
bytes.Name=name;
现在,当我看着SMBMESSAGE的价值,同时调试它显示NameSpace.Form1.SMB_MESSAGE
无里面的值。我也看不到一种方法来将值设置为SMBMESSAGE
。
如果我们不能分配值,那么为什么我们需要使用嵌套结构?
你'struct'名称是太可怕了。 – SLaks 2010-08-06 05:35:26
@SLaks,我想知道为什么? – Simsons 2010-08-06 05:37:53
绝对不应该在C#中使用全部大写。相反,您应该将它们命名为Message,MessageParameter,MessageData和DataBytes。 – SLaks 2010-08-06 05:41:29