C# 类静态成员变量 定义时初始化,不需要实例化一个对象初始化

    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            
            TestStaticList.ShowAll();
        }
    }

    internal class TestStaticList
    {
        static List<string> tmp = new List<string> { "hello", "world", "test" };
        internal static void ShowAll()
        {
            Console.Write("show all: ");
            foreach (var item in tmp)
            {
                Console.Write(item + " ");
            }
            Console.WriteLine("");
        }
    }

 

posted @ 2021-11-30 10:55  小小林林  阅读(173)  评论(0编辑  收藏  举报