不断获取不一致的可访问性错误C#
本文关键字:访问 错误 获取 不一致 | 更新日期: 2023-09-27 18:26:02
我知道这个问题已经在这个网站上提出并得到了回答。但是这些解决方案对我不起作用。尽管我正在将我的对象类设置为public,但我还是不断地收到这个错误。
这是我的代码:
public Shipment shipment;
public CreateMultipleShipments(Shipment shpmnt)
{
InitializeComponent();
shipment = new Shipment();
this.shipment = shpmnt;
txtBarcode0.Text = shipment.Barcode;
txtShpmntNr0.Text = shipment.Barcode2;
txtWeight0.Text = Convert.ToString(shipment.Weight);
txtVolume0.Text = Convert.ToString(shipment.Volume);
}
这就是我创建的类:
class Shipment
{
public int SendingID { get; set; }
public string Barcode { get; set; }
public string Barcode2 { get; set; }
public string PickupType { get; set; }
public int PickupAdrID { get; set; }
public string PickupCustomer { get; set; }
public string PickupAlias { get; set; }
public string PickupAttention { get; set; }
public int PickupRouteID { get; set; }
public string PickupRoutePart { get; set; }
public DateTime PickupDate { get; set; }
public DateTime PWindowFrom { get; set; }
public DateTime PWindowTo { get; set; }
public string DeliveryType { get; set; }
public int DeliveryAdrID { get; set; }
public string DeliveryCustomer { get; set; }
public string DeliveryAlias { get; set; }
public string DeliveryAttention { get; set; }
public int DeliveryRouteID { get; set; }
public string DeliveryRoutePart { get; set; }
public DateTime DeliveryDate { get; set; }
public DateTime DWindowFrom { get; set; }
public DateTime DWindowTo { get; set; }
public string Coli { get; set; }
public double Weight { get; set; }
public double Volume { get; set; }
public string Note { get; set; }
public string ServiceType { get; set; }
public int KM { get; set; }
public Shipment()
{
}
}
当我将发货初始化设置为公共时,我在以下两行上出现不一致的可访问性错误:
public Shipment shipment;
public CreateMultipleShipments(Shipment shpmnt)
我似乎找不到解决这个问题的办法。希望你们能帮助我。谢谢。
您的类Shipment
应声明为public
。当您没有指定任何修饰符时,默认值是内部的,这是不一致的
来自MSDNInternal is the default if no access modifier is specified.
public class Shipment {
public int SendingID { get; set; }
public string Barcode { get; set; }
public string Barcode2 { get; set; }
// ...etc
}
如果不向类添加修饰符,则默认修饰符为内部修饰符。
所以您的Shipment类是内部的,这与其他公共修饰符不一致。
将公共修饰符添加到您的Shipment类中以解决此问题。
您遇到的问题是,您只是将类声明为:
class Shipment
默认情况下,当排除辅助功能修饰符时,它默认为internal
。有关访问修饰符的解释,请参阅MSDN。
为了避免这种情况,您应该指定public
所需的访问修饰符,例如
public class Shipment