正如你所看到的,一切都設置爲公共的,但是編譯器說:爲什麼我在此C#代碼中得到「...由於其保護級別而無法訪問」編譯錯誤?
Shooting.inventoryWeapon.inventoryWeapon(Shooting.weapon, int)
無法訪問由於其保護級別。
此代碼在課堂上拍攝。
public enum weapon{gun,shotgun};
public struct inventoryWeapon{
weapon current;
int shotAmmo;
inventoryWeapon(weapon cur,int shAmmo){
current=cur;
shotAmmo=shAmmo;
}
}
public inventoryWeapon[] Inventory;
int weaponIndex=0;
void Start(){
Inventory=new inventoryWeapon[10];
Inventory[weaponIndex]= new inventoryWeapon(weapon.shotgun,30);
}
的[什麼是公共,私有,保護,並沒有什麼區別?(可能重複http://stackoverflow.com/questions/614818/what-is-the-difference-between-public-私人保護和沒有) –