可访问性不一致:基类比子类更难访问 [英] Inconsistent accessibility: base class is less accessible than child class

查看:95
本文介绍了可访问性不一致:基类比子类更难访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到了一本关于C#编程的书然后复制并粘贴了一些代码作为一个例子。

如果出现错误不一致的可访问性:基类比子类更不易访问。

I got a book about C# programming then copied and pasted some code as an example.
How ever the error "Inconsistent accessibility: base class is less accessible than child class" pop out.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _2_52
{
    class Program
    {
        static void Main(string[] args)
        {
            Rectangle rectangle = new Square(12);
            rectangle.Width = 10;
            rectangle.Height = 5;
            Console.WriteLine(rectangle.Area);
        }
    }
    class Rectangle
    {
        public Rectangle(int width,int height)
        {
            Width = width;
            Height = height;
        }
        public virtual int Height { get; set; }
        public virtual int Width { get; set; }
        public int Area
        {
            get { return Height * Width; }
        }
    }
    private class Square : Rectangle
    {
        public Square(int size):base(size,size)
        {

        }
        public override int Width
        {
            get
            {
                    return base.Width;
            }
            set
            {
                base.Width = value; base.Width = value;
            }
        }
    }
}



感谢您的更正。


Thanks for correcting it.

推荐答案

private class Square : Rectangle


这篇关于可访问性不一致:基类比子类更难访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆