using System ; 
delegate int MyDelegate( ) ; 
class B 
{ // 定义一个私有的函数: 
static int MyPrivateMethod() 
{ return 0 ; } 

public class A 
{ // 字段定义: 
public B myField = new B();// 错误: 类型B与A字段A.myField级别不同 
// 构造函数: 
public readonly B myConst = new B(); //错误: 类型B是仅读的 
//方法: 
public B MyMethod() 

return new B(); 

//属性: 
public B MyProp 

set { } 

public static B operator + (A m1, B m2) 

return new B(); 

static void Main() 

Console.Write("Compiled successfully"); 

} 看不懂它的错误解释,请大家帮帮忙

解决方案 »

  1.   

    添加public修饰就可以通过编译了.
    public class B  

      static int MyPrivateMethod()  
      { 
        return 0; 
      }  
    } 原因呢, 因为class A是public的, 其他assembly中可以看到class A对不对? 也就可以看到public B myField对不对?
    但是却得不到class B的定义因为Class B是只对assembly内可见的. 编译器就抱怨错误.至于第二个错误,  //错误: 类型B是仅读的  
    你能不能先确定是不是写错了? 
      

  2.   


    //这个委托你想干吗?
    delegate int MyDelegate( ) ;
    public class B
    { // 定义一个私有的函数:  
        static int MyPrivateMethod()
        {
            return 0;
        }
    }
    public class A
    {
        // 字段定义:  
        //public B myField = new B();// 错误: 类型B与A字段A.myField级别不同  
        //定义只读public属性
        private B myConst; //= new B(); //错误: 类型B是仅读的  
        //方法:  
        public B MyMethod()
        {
            return new B();
        }    public A()
        {
            myConst = new B();
        }
        //属性:  
        public B MyProp
        {
            get { return this.myConst; }
            //set { }
        }
        public static B operator +(A m1, B m2)
        {
            return new B();
        }
        static void Main()
        {
            string msg = "";
            //不明白你要实现什么..
            try
            {
                A a = new A();
                B b = new B();
                B ab= a + b;
                msg = "Compiled successfully";
            }
            catch (Exception ex)
            {
                msg = ex.Message;
            }        Console.WriteLine(msg);        //Console.Write("Compiled successfully");
        }
    }
      

  3.   

    这是我从网上摘落下来的
    具体能做什么我也不知道,因为是学习,就没有考虚这么多,只是把我的问题说出来
    “至于第二个错误,  //错误: 类型B是仅读的   
    你能不能先确定是不是写错了? 

    这句没有错 我是从vb到c#看起来确实困难,望大家体谅
    看看谁能说说第二个错误第一个gomoku说的差不多了呵呵
    谢谢大家