c# - 如何在 C# 中创建一个全局对象?

标签 c# .net global-variables

我想使我定义的类的对象成为全局对象,但我收到错误。 我正在做这样的事情:

namespace HotelSystem
{
    public static class GlobalVariables
    {
        public static login_log cashier = new login_log();
        public static List<customer> customer = new List<customer>();
    }
}

我得到这个错误:

Inconsistent accessibility: field type 'HotelSystem.Helpers.login_log' is less accessible than field 'HotelSystem.GlobalVariables.cashier'

Inconsistent accessibility: field type 'System.Collections.Generic.List<HotelSystem.Helpers.customer>' is less accessible than field 'HotelSystem.GlobalVariables.customer'

最佳答案

您是否尝试过错误提示?

将'public'添加到login_log类和customer类

关于c# - 如何在 C# 中创建一个全局对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22308796/

相关文章:

c# - 在 XAML 中绑定(bind) Itemscontrol 之外的属性

javascript - jQuery:为 map 创建全局变量

类中的 PHP 命名空间和全局变量问题

c++ - 我怎样才能避免把这个变量放在堆栈上?

c# - 在 C# 中覆盖 ToString 和使用隐式/显式转换运算符有什么区别?

c# - DynamicResource 的回退值

c# - 错误 "the exec task needs a command to execute"是什么意思?

.net - xUnit.NET 中的组合数据?

c# - 我如何从 Orchard 数据库中删除模块的数据?

C# "must declare a body because it is not marked abstract, extern, or partial"