2016-01-27 48 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

非常感謝,這個工作非常非常 –

相關問題