- Sessions state
- Application State
- Cache
- Cookie
- Hidden field
- Query strings
- Local Storage
public class normalclass{public static void staticmethodofnormalclass(){Console.WriteLine("this is static method of non static class");}}
We can call the method staticmethodofnormalclass directly with class name ie normalclass.staticmethodofnormalclass()
class MyErrorHandler : HandleErrorAttribute
{
public override void OnException(ExceptionContext filterContext)
{
Log(filterContext.Exception);
base.OnException(filterContext);
}
private void Log(Exception exception)
{
//log exception here..
}
}[MyErrorHandler]
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
}Static Class:-
You cannot create the instance of static class.
Loaded automatically by the .NET Framework common language runtime (CLR) when the program or namespace containing the class is loaded.
Static Class cannot have constructor.
We cannot pass the static class to method.
We cannot inherit Static class to another Static class in C#.
A class having all static methods.
Better performance (static methods are bonded on compile time)
Singleton:-
You can create one instance of the object and reuse it.
Singleton instance is created for the first time when the user requested.
Singleton class can have constructor.
You can create the object of singleton class and pass it to method.
Singleton class does not say any restriction of Inheritance.
We can dispose the objects of a singleton class but not of static class.
Methods can be overridden.
Can be lazy loaded when need (static classes are always loaded).
We can implement interface(static class can not implement interface).
Q46. If we have 3 types of constructor in code static, default, parametrized. In which order they will be called. Q47. What is GAC? Q48. ...