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(""); } }