Sto tentando di accedere a un campo static
dello struct
che ho già definito pubblico. Tuttavia, ho ancora "inaccessibile a causa del suo livello di protezione" Qualcuno può aiutarmi?C# Come accedere al campo statico di una struttura pubblica
public class Program
{
public struct AT_CMD
{
static int x = 7;
static byte[] cmd_mode = new byte[3] { 0x2B, 0x2B, 0x2B };
static byte[] end_device_assoc = new byte[4] { 0x41, 0x54, 0x41, 0x31 };
//should be 0 for end device, default is 0
static byte[] data_rate = new byte[4] { 0x41, 0x54, 0x42, 0x44 }; //3 for 9600, 5 for 38400
static byte[] channel = new byte[4] { 0x41, 0x54, 0x43, 0x48 }; //0x0B-0x1A
static byte[] Dest_addr_high = new byte[4] { 0x41, 0x54, 0x44, 0x48 }; //0 FOR 16bit
static byte[] Dest_addr_low = new byte[4] { 0x41, 0x54, 0x44, 0x4C };
static byte[] my_addr = new byte[4] { 0x41, 0x54, 0x4D, 0x59 }; // 0-0xFFFF
static byte[] carriage_return = new byte[1] { 0x0D };
}
static void Main()
{
int y = AT_CMD.x;
}
}
grazie mille, quindi anche statico, è privato ... giusto? – fiftyplus
@gpakillsme: No, tecnicamente il valore predefinito è 'internal', anche se la distinzione potrebbe non essere importante per il tuo caso. Vedere [here] (http://msdn.microsoft.com/en-us/library/ms173121.aspx) per ulteriori informazioni. –
@BlueRaja: In realtà, internal è l'impostazione predefinita per una struct/class non annidata (ovvero, 'struct AT_CMD' è uguale a' struct AT_CMD 'interno se non nidificato). L'impostazione predefinita per i membri classe/struct è 'private'. –