2016-01-27 49 views
-4

我有一个公共类,我试图在另一个项目中引用它。它有一个构造函数:由于其保护级别而无法访问公共类

namespace Stuff 
{ 
    struct Vector 
    { 
     public double x { get; set; } 
     public double y { get; set; } 
     public double z { get; set; } 

     public Vector (double ex, double why, double zee) 
     { 
      this.x = ex; 
      this.y = why; 
      this.z = zee; 
     } 

...

,我不断收到inaccessible due to protection level错误。

这是我怎样,我引用它在另一个项目:

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

namespace ProjectileMotion 
{ 
    class Projectile 
    { 
     private Vector acceleration = new Vector(0, 0, -9.8); //the acceleration is a vector now. 

...

类“向量”是在一个名为“东西”项目 - 它需要一个更好的名字。

+0

声明'Vector'结构为public并且再次尝试 – Zippy

+6

很明显它不是'public' –

+0

您的结构不是类,它不是公共的。为了公开添加'public struct Vector' – serhiyb

回答

7

您需要将您的struct定义为public

public struct Vector { ... } 

仅因为构造函数是公共的并不意味着类/结构也是公共的。

使用您当前的代码struct仅在包含装配中可访问,因为默认访问修改器是internal。然而,在那个集会中,这个班无处不在。

+0

非常感谢,这个工作非常非常 –

相关问题