Я получаю стек над ошибкой потока в моей программе. У меня есть класс с функциями и свойствами, для которых мне нужен мой неполный класс с текстовыми полями winform, флажками и т. Д., Чтобы иметь доступ. Когда я строю, это нормально, но я получаю ошибку времени выполнения. Он указывает на конструктор по умолчанию, который у меня есть и используется в winform, относительно того, где Visual Studio утверждает, что стек переполнен. код:Ошибка переполнения стека. using winforms
public class TeamCreator:Form
{
//fields
public string[] players=new string[12];
public int[] points=new int[12];
public int currentPlayerScore=0;
public TeamCreator()//default constructor
{
for (int i = 0; i < 11; i++)
{
this.players[i] = "";
this.points[i] = 0;
}
}
public TeamCreator(string[] teammates,int[] scores)//construct Team object with user input
{
this.players = teammates;
this.points = scores;
}
public void setTeammates(string player,int index)//set players array
{
this.players[index] = player;
}
public void setPoints(int[] scoreList)//set points array
{
this.points = scoreList;
}
public void setPlayerScore(int playerScore,int playerNum)//sets a specific player's score
{
this.points[playerNum] = playerScore;
}
public int[] getPoints()//obtain array of points
{
int[] listOfPoints=new int[12];
int i;
for(i=0;i<11;i++)
{
listOfPoints[i]=this.points[i];
}
return listOfPoints;
}
public int totalPoints()//gets total points
{
int total=0;
for(int i=0;i<11;i++)
{
total = this.points[i] + total;
}
return total;
}
public double meanPoints()//returns mean or average of total points
{
int total = this.totalPoints();
int mean = total/11;
return mean;
}
}
}
//winform code
namespace TeamClass
{
public partial class TeamClass:TeamCreator
{
public int indexOn = 0;
public int current = 0;
public TeamCreator newTeam = new TeamCreator();
public TeamClass()
{
InitializeComponent();
}
private void playerInput_MouseLeave(object sender, EventArgs e)//adds players to players array and to list
{
string playerName = playerInput.Text;
newTeam.setTeammates(playerName,this.indexOn);
playerList.Items.Add(playerName);
indexOn++;
}
TeamClass reopen = new TeamClass();
private void restart_CheckedChanged(object sender, EventArgs e)//allows user to restart program and make a new team
{
this.Visible = false;
reopen.Show();
}
private void playerScoreDisplay_CheckedChanged(object sender, EventArgs e)//displays currently selected player when checked
{
string currentPlayerSelected = newTeam.players[current];
MessageBox.Show("The current player selected is " + currentPlayerSelected + ".", "Current Player", MessageBoxButtons.OK);
}
private void playerList_SelectedIndexChanged(object sender, EventArgs e)
{
this.current = playerList.SelectedIndex;
}
private void scoreInput_MouseLeave(object sender, EventArgs e)//gets player score
{
int currentScore;
if (!Int32.TryParse(scoreInput.Text, out currentScore))
{
//tell user we can't parse the amount
if (MessageBox.Show("Text did not parse to an integer, please try again", "Invalid Argument", MessageBoxButtons.RetryCancel) == System.Windows.Forms.DialogResult.Cancel)
{
// leave method if they don't want to try again
return;
}
else
{
//set the focus on the control so user can fix error
scoreInput.Focus();
//As a convenience select all text
scoreInput.SelectAll();
//exit method
return;
}
}
newTeam.setPlayerScore(currentScore, current);
}
private void scoreInput_KeyPress(object sender, KeyPressEventArgs e)//makes sure numbers are being entered correctly for score
{
//only accept negative sign in first position
if ((e.KeyChar == '-') && ((sender as TextBox).Text.Length == 0))
{
if ((sender as TextBox).Text.Contains("-"))
e.Handled = true;
}
//Only accept numbers, one decimal, one negative sign (-) and the backspace
else if (!char.IsDigit(e.KeyChar) && !char.IsPunctuation(e.KeyChar) && !(e.KeyChar == 0x08))
{
e.Handled = true;
}
}
private void totalPointsDisplay_CheckedChanged(object sender, EventArgs e)//displays total points when checked
{
int total=newTeam.totalPoints();
MessageBox.Show("The total points for the team is " + total + ".", "Total Points", MessageBoxButtons.OK);
}
private void MeanPointsDisplay_CheckedChanged(object sender, EventArgs e)//displays mean points when checked
{
double avg=newTeam.meanPoints();
MessageBox.Show("The mean points for the team is " + avg + ".", "Mean Points", MessageBoxButtons.OK);
}
}
}
Любая помощь, почему я получаю эту ошибку и как исправить это были бы оценены. Я новичок в C#, поэтому не знаю, в чем проблема.
Start, глядя на все сообщение исключения, включая стек-следа. – Blorgbeard