Ошибка «Пространство имен не может непосредственно содержать такие члены, как поля или методы» - C#
Формулировка задачи:
Добрый день!
C# Visual Studio 2010
Программа выдает ошибки:
Ошибка 1 Пространство имен не может непосредственно содержать такие члены, как поля или методы
Ошибка 2 Требуется класс, делегат, перечисление, интерфейс или структура
Пример брал из SDK:
Подскажите, где ошибка, чего не хватает?
Так же необходимо, что бы программка опрашивала постоянно переменную ias И выводила мне ее в режиме реального времени. Спасибо!
Листинг программы
- using FsuipcSdk; // Help Studio.NET find Fsuipc class
- Fsuipc fsuipc = new Fsuipc(); // Instantiate our Fsuipc object
- bool result = false; // Return boolean for FSUIPC method calls
- int dwFSReq = 0; // Any version of FS is OK
- int dwOffset = 0x02BC; // Indicated airspeed memory offset
- int dwSize = 4; // Indicated airspeed memory size
- int token = 0; // Variable to hold returned token index
- int dwResult = 0; // Variable to hold returned results
- // Optional initialization
- fsuipc.FSUIPC_Initialization();
- // Open the connection to FSUIPC (and thus the simulator)
- // if result == true then everything worked OK
- result = fsuipc.FSUIPC_Open(dwFSReq, ref dwResult);
- // Submit a single read request
- // if result == true then everything worked OK
- result = fsuipc.FSUIPC_Read(dwOffset, dwSize, ref token, ref dwResult);
- // Process (actually perform) the request
- // if result == true then everything worked OK
- result = fsuipc.FSUIPC_Process(ref dwResult);
- // Get the returned value
- // if result == true then everything worked OK
- result = fsuipc.FSUIPC_Get(ref token, ref dwResult);
- // Adjust the IAS value as per "FSUIPC for Programmers.doc"
- int ias = dwResult * 128;
- // Close the FSUIPC connection
- fsuipc.FSUIPC_Close();
Листинг программы
- public void FSUIPC_Initialization() public bool FSUIPC_Open(int dwFSReq, ref int dwResult); int SIM_ANY for any supported by FSUIPC or equivalent
- int SIM_FS98 FS98
- int SIM_FS2K FS2000
- int SIM_FS2K2 FS2002
- int SIM_CFS2 CFS2
- int SIM_CFS1 CFS
- int SIM_FLY Fly! (not supported yet, and no promises implied! int FSUIPC_Version; // HIWORD is 1000 x Version Number, minimum 1998
- // LOWORD is build letter, with a = 1 etc.
- int FSUIPC_FS_Version; // SIM_FS98, SIM_FS2K etc -- see above public bool FSUIPC_Read(int dwOffset, int dwSize, ref int Token,
- ref int dwResult) public bool FSUIPC_Write(int dwOffset, byte param, ref int Token,
- ref int dwResult)
- public bool FSUIPC_Write(int dwOffset, short param, ref int Token,
- ref int dwResult)
- public bool FSUIPC_Write(int dwOffset, int param, ref int Token,
- ref int dwResult)
- public bool FSUIPC_Write(int dwOffset, long param, ref int Token,
- ref int dwResult)
- public bool FSUIPC_Write(int dwOffset, int dwSize, ref byte[] param,
- ref int Token, ref int dwResult) public bool FSUIPC_Get(ref int Token, ref byte Result)
- public bool FSUIPC_Get(ref int Token, ref short Result)
- public bool FSUIPC_Get(ref int Token, ref int Result)
- public bool FSUIPC_Get(ref int Token, ref long Result)
- public bool FSUIPC_Get(ref int Token, int dwSize, ref byte[] Result)using FsuipcSdk; // Help Studio.NET find Fsuipc class
- Fsuipc fsuipc = new Fsuipc(); // Instantiate our Fsuipc object
- bool result = false; // Return boolean for FSUIPC method calls
- int dwFSReq = 0; // Any version of FS is OK
- int dwOffset = 0x02BC; // Indicated airspeed memory offset
- int dwSize = 4; // Indicated airspeed memory size
- int token = 0; // Variable to hold returned token index
- int dwResult = 0; // Variable to hold returned results
- // Optional initialization
- fsuipc.FSUIPC_Initialization();
- // Open the connection to FSUIPC (and thus the simulator)
- // if result == true then everything worked OK
- result = fsuipc.FSUIPC_Open(dwFSReq, ref dwResult);
- // Submit a single read request
- // if result == true then everything worked OK
- result = fsuipc.FSUIPC_Read(dwOffset, dwSize, ref token, ref dwResult);
- // Process (actually perform) the request
- // if result == true then everything worked OK
- result = fsuipc.FSUIPC_Process(ref dwResult);
- // Get the returned value
- // if result == true then everything worked OK
- result = fsuipc.FSUIPC_Get(ref token, ref dwResult);
- // Adjust the IAS value as per "FSUIPC for Programmers.doc"
- int ias = dwResult * 128;
- // Close the FSUIPC connection
- fsuipc.FSUIPC_Close();using FsuipcSdk; // Help Studio.NET find Fsuipc class
- Fsuipc fsuipc = new Fsuipc(); // Instantiate our Fsuipc object
- bool result = false; // Return boolean for FSUIPC method calls
- int dwFSReq = 0; // Any version of FS is OK
- int token = 0; // Variable to hold returned token index
- int dwResult = 0; // Variable to hold returned results
- // Optional initialization
- fsuipc.FSUIPC_Initialization();
- // Open the connection to FSUIPC (and thus the simulator)
- // if result == true then everything worked OK
- result = fsuipc.FSUIPC_Open(dwFSReq, ref dwResult);
- // Set slew mode on (required prior to location writes)
- // if result == true then everything worked OK
- result = fsuipc.FSUIPC_Write(0x05DC, 1, ref token, ref dwResult);
- // Set latitude
- // if result == true then everything worked OK
- result = fsuipc.FSUIPC_Write(0x0564, 4454206, ref token, ref dwResult);
- result = fsuipc.FSUIPC_Write(0x0560, 901120000, ref token, ref dwResult);
- // Set longitude
- // if result == true then everything worked OK
- result = fsuipc.FSUIPC_Write(0x056C, -991553537, ref token, ref dwResult);
- result = fsuipc.FSUIPC_Write(0x0568, 219480064, ref token, ref dwResult);
- // Write the data to FS
- // if result == true then everything worked OK
- result = fsuipc.FSUIPC_Process(ref dwResult);
- // Close the FSUIPC connection
- fsuipc.FSUIPC_Close();
Решение задачи: «Ошибка «Пространство имен не может непосредственно содержать такие члены, как поля или методы»»
textual
Листинг программы
- System.Console.WriteLine(ias);
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д