   [.net] I don't get fix this initialization error
  Hi fellows.I've coded this to initialize the directX.public partial class Form1 : Form    {   private Device DirectDevice = null;   private PresentParameters[] PresParams = null;   Capabilities theCapabilities = Manager.GetDeviceCapabilities(0, DeviceType.Hardware);   public Form1()   { InitializeComponent();   }   private void InitiateDirectX()   { PresParams = new PresentParameters[1]; try {    PresParams[0].BackBufferFormat = Format.A8R8G8B8;    PresParams[0].BackBufferCount = 1;    PresParams[0].EnableAutoDepthStencil = true;    PresParams[0].DeviceWindowHandle = this.Handle;    PresParams[0].AutoDepthStencilFormat = DepthFormat.D16;    PresParams[0].FullScreenRefreshRateInHz = 0;    PresParams[0].IsWindowed = true;    PresParams[0].SwapEffect = SwapEffect.Discard; } catch (Exception ex) {    MessageBox.Show(this, ex.ToString(), "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); } CreateFlags theFlags = new CreateFlags(); theFlags = (CreateFlags.HardwareVertexProcessing | CreateFlags.SoftwareVertexProcessing); try {    DirectDevice = new Device(0, DeviceType.Hardware, this.Handle, theFlags, PresParams);    MessageBox.Show(this, "Device created successfully", "Success", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } catch (DirectXException DX) {    MessageBox.Show(this, DX.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } DirectDevice.SetRenderState(RenderStates.CullMode, true); DirectDevice.SetRenderState(RenderStates.ZEnable, true); DirectDevice.SetRenderState(RenderStates.ZBufferWriteEnable, true);   }   public void Renderirze()   { DirectDevice.Clear((ClearFlags.ZBuffer | ClearFlags.Target), Color.FromArgb(0, 128, 128, 128), 0, 0); DirectDevice.BeginScene(); DirectDevice.EndScene();   }    }My problem is that the compiler tells me that the PresentParameters is don't initialized. The exception is System.NullReferenceException. Why? If I created and instantiated the PresentParameters, why this guy shows me this error: "Object reference not set to an instance of an object"   
  You've only initialized the PresParams array, but PresParams[0] is still uninitialized and hence null (it's a class, not a struct). You can fix this by adding the following line before your try statement:PresParams[0] = new PresentParameters();It's not really necessary to pass in an array of present parameters though, a single PresentParameters object will do too.   ;  Thanks remigius, I only change the PresentParameters array to an instance of a single object and works.   