I have a web application where I would like to pull user settings from a database and store them for Global access. Would it make more sense to store the data in a Singleton, or a Session object? What's the difference between the two?
Session object, definitely.
Singletons exist at the process level. This means that if you have 20 users accessing your site at any given moment, they're using the same singleton object. It's difficult to get used to this concept if you're not doing web development a lot.
Sessions exist at the user level. That means you can store data per user, not per process.
Ref:
http://stackoverflow.com/questions/2821941/session-vs-singleton-pattern
Monday, October 21, 2013
Tuesday, October 8, 2013
Thursday, October 3, 2013
What use of Is & as Operator?
"Is" operator
It is useful when we want to check whether one object belongs to particular class or not?. Have a look on below code usingclass Test
{
public string Name { get; set; }
}
class Test1:Test
{
public string Surname { get; set; }
}
class Program
{
public static void Main(String[] args)
{
Test t = new Test();
if (t is Test1)
Console.WriteLine("t is object of Test1");
else
Console.WriteLine("t is not object of Test1");
Console.ReadLine();
}
}
"as" operator
as operator is useful when we want to convert one type to another type. But we have to keep in mind that both type should be compatible. Means by applying boxing and unboxing concept it should possible to convert one type to another type.Let’s see by example.
class Test
{
public Test() { }
public string Name { get; set; }
} class Test1 : Test
{
public Test1() { }
public string Surname { get; set; }
}
class Program
{
public static void Main(String[] args)
{
Test1 t1 = new Test1();
t1.Name = "Mohan";
t1.Surname = "subramanian";
Test t = new Test();
t = t1 as Test;
Console.WriteLine("Name:-" + t.Name);
Console.ReadLine();
}
}
Here is sample output: Name:- Mohan
Subscribe to:
Posts (Atom)
Abstract Factory Vs Factory Method
Abstract Factory Provides an interface for creating families of related or dependent objects without specifying their concrete classes ...
-
Stored Procedures are pre-compile objects which are compiled for first time and its compiled format is saved which executes (compiled code) ...
-
Web API 1. This is the new framework for building HTTP services with easy and simple way. 2. Web API is open source an ideal ...
-
There are many technologies used to build .NET Web applications. To build effective application-level authentication and authorization s...