Results 1 to 2 of 2

Thread: Get an error saying that array is obj when it should return a bool...

  1. #1
    103
    posts
    Registered User

    Get an error saying that array is obj when it should return a bool...

    Alright, i am working with an array and some keyvalues. and i keep getting an error from the last funciton saying:

    Code:
    Cannot implicitly convert type 'object' to 'bool'. An explicit conversion exists (are you missing a cast?) (CS0266)
    Code:
    using System;
    using System.Collections.Generic;
    using System.Drawing;
    using System.Windows.Forms;
    using System.Diagnostics;
    namespace Test{
    /// <summary>
    /// Description of MainForm.
    /// </summary>
    public partial class MainForm : Form
    {
     
    int i = 0;
    private bool running = true;
    public Array keyArray = Array.CreateInstance(typeof(bool), 2, 222);
    public MainForm()
    {
    //
    // The InitializeComponent() call is required for Windows Forms designer support.
    //
     
    InitializeComponent();
     
    for (i=0; i<222; i++)
    {
    keyArray.SetValue(false, 0, i);
    }
     
    onEnterFrame();
    }
    public void onEnterFrame()
    {
    while(running)
    {
    if(keyisdown(39))
    {
    Debug.WriteLine("Right is pressed");
    }
    }
    }
    protected override void OnKeyDown(KeyEventArgs e)
    {
    Debug.WriteLine(e.KeyValue);
    keyArray.SetValue(true, 0, e.KeyValue);
    }
    protected override void OnKeyUp(KeyEventArgs e)
    {
    keyArray.SetValue(false, 0, e.KeyValue);
    }
    public bool keyisdown(int X)
    {
    return keyArray.GetValue(0, X);
    }

    i'm not sure how to fix that little problem
    Last edited by DrRobot; June 28th, 2008 at 06:45 PM. Reason: Solved.

  2. #2
    103
    posts
    Registered User
    Nevermind, i have it figured out. i should've just made the Array a bool[,] (i did, thats how it was fixed).

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012