I have this code in c++ to do this but I want to do the same in C# but it's not working and I can't figure it out why?
class Numero
{
public:
static int num;
Numero()
{
cout<<num++<<" ";
}
};
int Numero::num=1;
int main()
{
int n;
cout<<"Type n: ";
cin>>n;
Numero obj[n];
return 0;
}
this print "1 2 3 4 5 .... n" but in C#
class numero
{
public static int num {get; set;}
public numero()
{
Console.WriteLine(num);
num++;
}
}
class Program
{
static void Main(string[] args)
{
numero.num=1;
Console.WriteLine("Type 'n'");
int n = int.Parse( Console.ReadLine());
Console.WriteLine("Printing to: {0}", n);
numero[] num_1 = new numero[n];
Console.WriteLine("End");
Console.ReadLine();
}
}
I tried in diferent ways but the only I get is:
Type 'n' 10 Printing to: 10 End
any idea in how to make it works? and why when creating the class numero it's not calling the numero constuctor??