Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 不包含构造函数 类型定义 使用系统; 公共枚举方向{右、左、前}; 查哈帕类 { 私人互联网; 私人内部高度; 私家侦探; 私人内部协调; 公共查哈帕(整数a、整数b、整数x、整数y) { 年龄=a; 高度=b; cordinates_x=x; cordinates_y=y; } 公共查哈帕(内部c、内部d) { 年龄=c; 高度=d; cordinates_x=0; cordinates_y=0; } 公共信息 { 获取{返回年龄;} } 公共内部高度 { 获取{返回高度;} } 公共国际协调委员会 { 获取{return cordinates_x;} 设置{cordinates_x=value;} } 公共国际协调委员会 { 获取{return cordinates_y;} 设置{if(value>0)cordinates_y=value;} } 公共空间移动(方向) { 如果(方向==前进方向) Cordinates_y++; else if(方向==方向.右) Cordinates_x++; else if(方向==方向.左) Cordinates_x--; } 职业马:查哈帕 { 公共场所是野生的; 公共无效跳转(int x) { x=Cordinates_y; Cordinates_y+=5; } 公开作废印刷品() { 控制台.WriteLine(“马信息:年龄,+Age+”,高度:+Height+,Wild:+is_Wild+”,X:+Cordinates_X+”,Y:+Cordinates_Y); } } } 用法 类程序 { 静态void Main(字符串[]参数) { 整数,x,y,minAge=0; 内部高度; 布尔野生; 对于(int i=0;i年龄) { minAge=年龄; } } Console.WriteLine(); 马ob=新马(); ob.Jump(minAge); ob.move(); ob.Print(); Console.ReadKey(); } }_C#_Class_Constructor - Fatal编程技术网

C# 不包含构造函数 类型定义 使用系统; 公共枚举方向{右、左、前}; 查哈帕类 { 私人互联网; 私人内部高度; 私家侦探; 私人内部协调; 公共查哈帕(整数a、整数b、整数x、整数y) { 年龄=a; 高度=b; cordinates_x=x; cordinates_y=y; } 公共查哈帕(内部c、内部d) { 年龄=c; 高度=d; cordinates_x=0; cordinates_y=0; } 公共信息 { 获取{返回年龄;} } 公共内部高度 { 获取{返回高度;} } 公共国际协调委员会 { 获取{return cordinates_x;} 设置{cordinates_x=value;} } 公共国际协调委员会 { 获取{return cordinates_y;} 设置{if(value>0)cordinates_y=value;} } 公共空间移动(方向) { 如果(方向==前进方向) Cordinates_y++; else if(方向==方向.右) Cordinates_x++; else if(方向==方向.左) Cordinates_x--; } 职业马:查哈帕 { 公共场所是野生的; 公共无效跳转(int x) { x=Cordinates_y; Cordinates_y+=5; } 公开作废印刷品() { 控制台.WriteLine(“马信息:年龄,+Age+”,高度:+Height+,Wild:+is_Wild+”,X:+Cordinates_X+”,Y:+Cordinates_Y); } } } 用法 类程序 { 静态void Main(字符串[]参数) { 整数,x,y,minAge=0; 内部高度; 布尔野生; 对于(int i=0;i年龄) { minAge=年龄; } } Console.WriteLine(); 马ob=新马(); ob.Jump(minAge); ob.move(); ob.Print(); Console.ReadKey(); } }

C# 不包含构造函数 类型定义 使用系统; 公共枚举方向{右、左、前}; 查哈帕类 { 私人互联网; 私人内部高度; 私家侦探; 私人内部协调; 公共查哈帕(整数a、整数b、整数x、整数y) { 年龄=a; 高度=b; cordinates_x=x; cordinates_y=y; } 公共查哈帕(内部c、内部d) { 年龄=c; 高度=d; cordinates_x=0; cordinates_y=0; } 公共信息 { 获取{返回年龄;} } 公共内部高度 { 获取{返回高度;} } 公共国际协调委员会 { 获取{return cordinates_x;} 设置{cordinates_x=value;} } 公共国际协调委员会 { 获取{return cordinates_y;} 设置{if(value>0)cordinates_y=value;} } 公共空间移动(方向) { 如果(方向==前进方向) Cordinates_y++; else if(方向==方向.右) Cordinates_x++; else if(方向==方向.左) Cordinates_x--; } 职业马:查哈帕 { 公共场所是野生的; 公共无效跳转(int x) { x=Cordinates_y; Cordinates_y+=5; } 公开作废印刷品() { 控制台.WriteLine(“马信息:年龄,+Age+”,高度:+Height+,Wild:+is_Wild+”,X:+Cordinates_X+”,Y:+Cordinates_Y); } } } 用法 类程序 { 静态void Main(字符串[]参数) { 整数,x,y,minAge=0; 内部高度; 布尔野生; 对于(int i=0;i年龄) { minAge=年龄; } } Console.WriteLine(); 马ob=新马(); ob.Jump(minAge); ob.move(); ob.Print(); Console.ReadKey(); } },c#,class,constructor,C#,Class,Constructor,我在Visual Studio中遇到以下错误: “Chaharpa”不包含接受0个参数的构造函数 找不到类型或命名空间名称“horse”(是否缺少using指令或程序集引用?) 找不到类型或命名空间名称“horse”(是否缺少using指令或程序集引用?) 在类Chaharpa中定义了两个构造函数,它们都接受参数。 创建自己的构造函数将覆盖默认构造函数。 通常,当从基类继承时,您希望使用用于初始化基类的参数初始化继承类,请详细了解这一点 Chaharpa和Chaharpa类中的horse类不是

我在Visual Studio中遇到以下错误:

“Chaharpa”不包含接受0个参数的构造函数

找不到类型或命名空间名称“horse”(是否缺少using指令或程序集引用?)

找不到类型或命名空间名称“horse”(是否缺少using指令或程序集引用?)

  • 在类
    Chaharpa
    中定义了两个构造函数,它们都接受参数。 创建自己的构造函数将覆盖默认构造函数。 通常,当从基类继承时,您希望使用用于初始化基类的参数初始化继承类,请详细了解这一点

  • Chaharpa
    Chaharpa
    类中的
    horse
    类不是公共的。 将课程
    horse
    Chaharpa
    更改为公共,并以以下方式访问:
    Chaharpa.horse ob=new Chaharpa.horse()
    这是正确的方法

  • 以下是对代码的一些缓解措施:

    using System;
    using System.ComponentModel;
    
    public enum Direction
    { Right, Left, Forward };
    public class Chaharpa
    {
        private int age;
        private int height;
        private int cordinates_x;
        private int cordinates_y;
        public Chaharpa()
        {
        }
    
        public Chaharpa(int a, int b, int x, int y)
        {
            age = a;
            height = b;
            cordinates_x = x;
            cordinates_y = y;
        }
        public Chaharpa(int c, int d)
        {
            age = c;
            height = d;
            cordinates_x = 0;
            cordinates_y = 0;
        }
        public int Age
        {
            get { return age; }
        }
    
        public int Height
        {
            get { return height; }
        }
    
        public int Cordinates_x
        {
            get { return cordinates_x; }
            set { cordinates_x = value; }
        }
        public int Cordinates_y
        {
            get { return cordinates_y; }
            set { if (value > 0) cordinates_y = value; }
        }
    
        public void Move(Direction direction)
        {
            if (direction == Direction.Forward)
                Cordinates_y++;
            else if (direction == Direction.Right)
                Cordinates_x++;
            else if (direction == Direction.Left)
                Cordinates_x--;
        }
        public class horse : Chaharpa
        {
            public bool is_wild;
    
            public void Jump(int x)
            {
                x = Cordinates_y;
                Cordinates_y += 5;        
            }
    
            public void move()
            {
                throw new NotImplementedException();
            }
    
            public void Print()
            {
                Console.WriteLine("Horse Information: Age," + Age + ", Height: " + Height + ", Wild: " + is_wild + ", X: " + Cordinates_x + ", Y: " + Cordinates_y);
            }
        }
    }
    
    
    class Program
    {
        static void Main(string[] args)
        {
            int age, x, y, minAge = 0;
            int height;
            bool wild;
    
            for (int i = 0; i < 3; i++)
            {
    
                Console.WriteLine("Horse #" + (i + 1));
    
                Console.Write("Enter Age: ");
                age = int.Parse(Console.ReadLine());
                Console.Write("Enter Height: ");
                height = int.Parse(Console.ReadLine());
                Console.Write("Enter X: ");
                x = int.Parse(Console.ReadLine());
                Console.Write("Enter Y: ");
                y = int.Parse(Console.ReadLine());
                Console.Write("Is Wild: ");
                wild = bool.Parse(Console.ReadLine());
    
                minAge = age;
                if (minAge > age)
                {
                    minAge = age;
                }
            }
            Console.WriteLine();
    
            Chaharpa.horse ob = new Chaharpa.horse();
    
            ob.Jump(minAge);
                    
            // You can call the Move defined in Chaharpa
            ob.Move(<PASS DIRECTION PARAMETER HERE>);
    
            ob.Print();
    
            Console.ReadKey();
    
        }
    }
    
    使用系统;
    使用系统组件模型;
    公共枚举方向
    {右、左、前};
    公共类查哈帕
    {
    私人互联网;
    私人内部高度;
    私家侦探;
    私人内部协调;
    公共查哈帕()
    {
    }
    公共查哈帕(整数a、整数b、整数x、整数y)
    {
    年龄=a;
    高度=b;
    cordinates_x=x;
    cordinates_y=y;
    }
    公共查哈帕(内部c、内部d)
    {
    年龄=c;
    高度=d;
    cordinates_x=0;
    cordinates_y=0;
    }
    公共信息
    {
    获取{返回年龄;}
    }
    公共内部高度
    {
    获取{返回高度;}
    }
    公共国际协调委员会
    {
    获取{return cordinates_x;}
    设置{cordinates_x=value;}
    }
    公共国际协调委员会
    {
    获取{return cordinates_y;}
    设置{if(value>0)cordinates_y=value;}
    }
    公共空间移动(方向)
    {
    如果(方向==前进方向)
    Cordinates_y++;
    else if(方向==方向.右)
    Cordinates_x++;
    else if(方向==方向.左)
    Cordinates_x--;
    }
    公共级马:查哈帕
    {
    公共场所是野生的;
    公共无效跳转(int x)
    {
    x=Cordinates_y;
    Cordinates_y+=5;
    }
    公开作废动议()
    {
    抛出新的NotImplementedException();
    }
    公开作废印刷品()
    {
    控制台.WriteLine(“马信息:年龄,+Age+”,高度:+Height+,Wild:+is_Wild+”,X:+Cordinates_X+”,Y:+Cordinates_Y);
    }
    }
    }
    班级计划
    {
    静态void Main(字符串[]参数)
    {
    整数,x,y,minAge=0;
    内部高度;
    布尔野生;
    对于(int i=0;i<3;i++)
    {
    Console.WriteLine(“Horse#”+(i+1));
    控制台。写入(“输入年龄:”;
    age=int.Parse(Console.ReadLine());
    控制台。写入(“输入高度:”;
    height=int.Parse(Console.ReadLine());
    Console.Write(“输入X:”);
    x=int.Parse(Console.ReadLine());
    控制台。写入(“输入Y:”;
    y=int.Parse(Console.ReadLine());
    控制台。写(“是野生的:”;
    wild=bool.Parse(Console.ReadLine());
    minAge=年龄;
    
    I am parent
    I am child
    
    I am outer
    I am inner