繁体   English   中英

为什么我不能实例化我的类,但我可以在另一个项目中?

[英]Why cant I instantiate my class, but I can in another project?

我正在尝试实例化我的“边界”类,但是当我在主类中输入它时它没有显示出来。 但是,我将该类添加到了过去的项目中,并且一切正常,因此它与我的代码无关。 我是 c# 的新手,想知道是否有一个简单的解决方法。

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace Game1
{
    class Boundries
    {
        public int boundY, boundX, boundWidth, boundLength;

        public Boundries(Rectangle bRectangle, int intX, int intY, int intWidth, int intLength)
        {
            boundY = intY;
            boundX = intX;
            boundWidth = intWidth;
            boundLength = intLength;
        }
    }
}

这门课在我过去的项目中工作得很好,但在我的新项目中却没有。

根据这个( https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/access-modifiers

直接在命名空间内声明的类和结构(换句话说,不嵌套在其他类或结构中)可以是公共的或内部的。 如果未指定访问修饰符,则默认为 Internal。

您无法从其他项目中实例化它,因为您没有为您的班级设置“公共”。

public class Boundries
{
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM