티스토리 뷰

반응형

[C#/wpf/winform] Singleton(싱글톤) 코드(복사해서 사용하기)

 

#싱글톤 구현

 public class OSCReceiverHelper
    {
        private static OSCReceiverHelper _instance { get; set; }
        public static OSCReceiverHelper Instance
        {
            get
            {
                return _instance ?? (_instance = new OSCReceiverHelper());
            }
        }

        public void Test()
        {
            Debug.WriteLine("Helloworld");
        }
    }

 

#싱글톤 사용

 public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        public void SingletonTest()
        {
            OSCReceiverHelper.Instance.Test();
        }
    }

 

#c# #wpf #winform #singleton #싱글톤

반응형
댓글
반응형