Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
不断获取不一致的可访问性错误C#_C#_.net - Fatal编程技术网

不断获取不一致的可访问性错误C#

不断获取不一致的可访问性错误C#,c#,.net,C#,.net,我知道这个问题已经在这个网站上提出并得到了回答。但这些解决方案对我不起作用。尽管我正在将对象类设置为public,但仍不断出现此错误 这是我的代码: public Shipment shipment; public CreateMultipleShipments(Shipment shpmnt) { InitializeComponent(); shipment = new Shipment(); this.shipment = shpmnt; txtBarcod

我知道这个问题已经在这个网站上提出并得到了回答。但这些解决方案对我不起作用。尽管我正在将对象类设置为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时,我在这两行上遇到不一致的可访问性错误:

public Shipment shipment;
public CreateMultipleShipments(Shipment shpmnt)

我似乎找不到解决这个问题的办法。希望你们能帮助我。谢谢。

您的班级
货物应声明为
公共
。不指定任何修饰符时的默认值为内部,这是不一致性
从…起 如果未指定访问修饰符,则默认为
Internal。

public class Shipment {
    public int SendingID { get; set; }
    public string Barcode { get; set; }
    public string Barcode2 { get; set; } 
    // ...etc
}

您的类
装运
应声明为
公共
。不指定任何修饰符时的默认值为内部,这是不一致性
从…起 如果未指定访问修饰符,则默认为
Internal。

public class Shipment {
    public int SendingID { get; set; }
    public string Barcode { get; set; }
    public string Barcode2 { get; set; } 
    // ...etc
}

如果不向类添加任何修改器,则默认修改器为内部修改器

因此,您的装运类是内部的,这与其他公共修饰符不一致


将公共修饰符添加到装运类以解决此问题。

如果未向类添加修饰符,则默认修饰符为内部修饰符

因此,您的装运类是内部的,这与其他公共修饰符不一致


将public修饰符添加到您的装运类以解决此问题。

您遇到的问题是,您只是将您的类声明为:

class Shipment
默认情况下,排除辅助功能修改器时,它默认为
internal
。有关访问修饰符的说明,请参见

为了避免这种情况,您应该指定在您的案例中所需的访问修饰符
public
,例如

public class Shipment

您遇到的问题是,您只是将类声明为:

class Shipment
默认情况下,排除辅助功能修改器时,它默认为
internal
。有关访问修饰符的说明,请参见

为了避免这种情况,您应该指定在您的案例中所需的访问修饰符
public
,例如

public class Shipment

感谢您澄清此问题。感谢您澄清此问题。请编辑您的答案,添加有关代码如何工作以及如何解决OP问题的解释。许多SO海报都是新手,不会理解您发布的代码。请编辑您的答案,添加关于您的代码如何工作以及如何解决OP问题的解释。许多SO海报都是新手,不会理解您发布的代码。