I have a simple application in C#. When I ran the code I am not getting the expected result?.I am getting 2,2,1 but i was expecting 1,2,3
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication12
{
class Program
{
static void Main(string[] args)
{
MyList<int> list1 = new MyList<int>();
MyList<int> list2 = new MyList<int>();
MyList<double> list3 = new MyList<double>();
Console.WriteLine(list1.GetCount());
Console.WriteLine(list2.GetCount());
Console.WriteLine(list3.GetCount());
}
}
public class MyList<T>
{
static int _count;
public MyList()
{
_count++;
}
public int GetCount()
{
return _count;
}
}
}
The result is as I expect
This MSDN blog post tells