Ошибка System.StackOverflowException - C#
Формулировка задачи:
Ошибка вылезает при вводе любого значения.
Делал симулятор броска монетки
using System;
namespace CoinFlip
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Введите количество попыток");
int a = int.Parse(Console.ReadLine());
UI NoA = new UI();
NoA.NumOfAttmepts = a;
UI answer = new UI();
int ans = answer.getCS();
Console.WriteLine(ans);
Console.ReadKey();
}
}
}
]using System;
namespace CoinFlip
{
class Random
{
protected byte CoinSide;
public byte setCoinSide()
{
int k = 0;
int j = 0;
for (int i = 0; i < 1000; i++)
{
long ms = DateTime.Now.Millisecond;
if(ms>500)
{
k++;
}
else
{
j++;
}
}
if(k==j)
{
CoinSide = 2;
}
if(k>j)
{
CoinSide = 1;
}
else
{
CoinSide = 0;
}
return CoinSide;
}
}
}using System;
namespace CoinFlip
{
class UI:Random
{
public int NumOfAttmepts
{
get
{
return NumOfAttmepts;
}
set
{
NumOfAttmepts = value;
}
}
public int getCS()
{
string equal = null;
int head = 0;
int tail = 0;
for(int i=0;i<NumOfAttmepts;i++)
{
Random CS = new Random();
byte x = CS.setCoinSide();
if(x==1)
{
head++;
}
else if(x==0)
{
tail++;
}
if (x == 2)
{
equal = "Орел и решка выпали одинаковое кол-во раз";
}
}
if (head > tail)
return head;
else
return tail;
}
}
}Решение задачи: «Ошибка System.StackOverflowException»
textual
Листинг программы
public int NumOfAttmepts { get; set; }