Hi, recently i've got a dispute about using static methods in a class that is used by hundreds threads. In my opinion the "first" solution has no special benefits except it is easier to use for the client of class but i have been told that it is extremely bad idea and I have to use the "second" solution. Can anyone give me clear explanation why i'm so wrong? Thanks a lot!
PS Let's assume that dictionary is thread safe.
class A
{
static Dictionary<int, string> m_dic = new Dictionary<int, string>();
public static string GetData1(int nKey)
{
return m_dic[nKey];
}
public string GetData2(int nKey)
{
return m_dic[nKey];
}
}
//these func are called from threads...
void ThreadFunc1()
{
print A.GetData1(1);
}
void ThreadFunc2()
{
A a = new A();
print a.GetData2(1);
}
Regards, Leonid