2
The pattern Multithread Singleton serves me in order to enable the use of "global variables" in my application. Its use occurs through the resources of get
and set
, as it is possible to notice.
How similarly, I can do the same with a variable of type Dictionary
?
using System;
namespace Program
{
class Global
{
public sealed class Session
{
private static volatile Session instance;
private static object sync = new Object();
private Session() { }
public static Session Instance
{
get
{
if (instance == null)
{
lock (sync)
{
if (instance == null)
{
instance = new Session();
}
}
}
return instance;
}
}
public bool glb_login { get; set; }
public string UserID { get; set; }
public string IPAddress { get; set; }
public string PortName { get; set; }
}
}
}
as far as I know a
Dictionary
is not a serializable element, you would have to implement your own serialization for it. If you want to serialize, it would be easier to use a simpler structure, likeIList
for example– Ricardo Pontual
Caio, I don’t know if it helps you, but there is an example in 2 parts of C# Singleton in Vbmania, namely: DESIGN PATTERN - SINGLETON PART #1 - http://www.vbmania.com.br/index.php?modulo=alhe&id=8830
– FabioIn
@Fabioin. I thank you, but I can not access the content for not having registration on the site.
– Caio de Paula Silva
@Caiodepaulasilva, registration is 100% free...
– FabioIn