ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

What is the difference between singleton pattern and static class?when i use static class and when i use singleton pattern?

user-image
تم إضافة السؤال من قبل mohd ikram , Software Engineer , VSK IT Services Pvt. Ltd.
تاريخ النشر: 2016/08/04
Mudassir Idrees
من قبل Mudassir Idrees , .NET Full Stack Developer , Nex-Operations (Pvt) Ltd

Static Class:

  1. You cannot create the instance of static class.
  2. Loaded automatically by the .NET Framework common language runtime (CLR) when the program or namespace containing the class is loaded.
  3. Static Class cannot have constructor.
  4. We cannot pass the static class to method.
  5. We cannot inherit Static class to another Static class in C#.

Singleton:

  1. You can create one instance of the object and reuse it.
  2. Singleton instance is created for the first time when the user requested.
  3. Singleton class can have constructor.
  4. You can create the object of singleton class and pass it to method.
  5. Singleton class does not say any restriction of Inheritance.
  6. We can dispose the objects of a singleton class but not of static class.

المزيد من الأسئلة المماثلة