using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Drawing;namespace tetris
{
    
    class BlockInfo
    {
        private BitArray _id; 
        private Color _bColor
  ......................
 }
上面这个是我创建的一个类
然后我想在新创建的类中使用这个上面这个类 class BlockInfo ,新创建的类如下:
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Drawing;
 namespace tetris
{
    class InfoArr
    {
      ............
     
        public BlockInfo this[int index]  //索引器,根据下标返回一个BlockInfo
        {
            get
            {
                return (BlockInfo)info[index];
            } 
...........}
}
  错误 1 找不到类型或命名空间名称“BlockInfo”(是否缺少 using 指令或程序集引用?) D:\vs205.net\progject\tetris\tetris\InfoArr.cs 22 16 tetris

解决方案 »

  1.   

    public class BlockInfo 用修饰下
      

  2.   


    class BlockInfo//此类用来 存放 单个砖块信息的类
        {
            private BitArray _id;//用来存放砖块的样式
            public BitArray Id
            {
                get { return _id; }
                set { _id = value; }
            }
            private Color _bcolor;//用来存放砖块的颜色        public Color BColor
            {
                get { return _bcolor; }
                set { _bcolor = value; }
            }
            public BlockInfo(BitArray bArray, Color col)
            {
                _id = bArray;
                _bcolor = col;
            }
            public string GetIdStr()
            {
                StringBuilder s = new StringBuilder();
                foreach (bool b in _id)
                {
                    s.Append(b? "1":"0");
                }
                return s.ToString();
            }
            public string  GetColorStr()
            {
                return Convert.ToString(_bcolor.ToArgb());
            } class InfoArr
        {
            private ArrayList info = new ArrayList();
            private int _length=0;
            public int Length
            { 
                get{return _length ;}
            }
            public BlockInfo this[int index]
            { 
                get
                {
                    return (BlockInfo)info [index];
                }
                
            }
            public string this[string id]
            {
                set 
                {
                    if (value == "")
                        return;
                    for (int i = 0; i < info.Count; i++)
                    {
                        if (((BlockInfo)info[i]).GetIdStr() == id)
                        {
                            try
                            {
                                ((BlockInfo)info[i]).BColor = Color.FromArgb(Convert.ToInt32(value));//经过强制类型转换,此时的info已经变成BlockInfo的一个对象了,这是可以直接调用它的方法!
                            }
                            catch (System.FormatException)
                            {
                                MessageBox.Show("xml文档,颜色信息有无!");
                            }
                        }
                    }
                }
            }
            public BitArray StrToBit(string id)
            {
                if (id.Length != 25)
                {
                    throw new System.FormatException("砖块样式不合法!");
                }
                BitArray ba = new BitArray(25);
                for (int i = 0; i < 25; i++)
                {
                    ba[i] = (id[i] == '0') ? false : true;
                }
                return ba;
            }
            public void Add(BitArray id,Color bColor)
            {
                if (id.Length != 25)
                {
                    throw new System.FormatException("砖块信息有误!");
                }
                info.Add(new BlockInfo (id,bColor));
                _length++;        }
            public void Add(string id,string bColor)
            {
                Color temp;
                if (!(bColor == ""))
                {
                    temp = Color.FromArgb(Convert.ToInt32(bColor));//把字符型的颜色转化成整型的颜色
                }
                else
                {
                    temp = Color.Empty;//颜色值 为空!
                }
                info.Add(new BlockInfo ((StrToBit (id)),temp ));
                _length++;
            }    }你这是做的一个俄罗斯方块的吧,我也见过这个源码。我认为你的这个代码没为题啊,这是我的源码,程序没问题。
      

  3.   

    楼上很强。别人问一个问题,你怎么知道是俄罗斯方块?楼主:2楼的是正解。类要public,其他类才可以访问。索引这个东西,初学只需要了解一下了。你建了索引,还需要继承IEnumerable,实现foreach的遍历。这样才好用。
      

  4.   

    也没发现问题出在那既然都是同一个namespace下的
    没道理BlockInfo用不了的

      

  5.   

    我加了Public 还是不行啊 55555555
      

  6.   


    没看到 命名空间吗??  tetris  啥意思??知道不??不知道的看看这个:http://iask.sina.com.cn/b/11041272.html 
      

  7.   


    没看到 命名空间吗??  tetris  啥意思??知道不??不知道的看看这个:http://iask.sina.com.cn/b/11041272.html 
      

  8.   

    加上using System.Collections;就可以了