Dizileri öğrenmeye çalışıyorum ve tüm dizilerimi girdikten sonra metin kutumda gösterilmesinin neden neden olduğunu anlayamıyorum. İşte Öğelerim, diziye bir sayı girdikten sonra neden 0?
İştepublic Form1()
{
InitializeComponent();
}
int[] a = new int[10]; //global int!!!
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void btn_Enter_Click(object sender, EventArgs e)
{
//all elements show as 0 but why ??? come back to this later tonight!
string input;
for (int place = 0; place < 10; place++)
{
input = null;
My_Dialogs.InputBox("User Input Request!", "Please enter a number to be stored in element " + place + " : ", ref input);
Int32.TryParse(input, out a[place]);
}
}
private void btn_display_Click(object sender, EventArgs e)
{
for (int place = 0; place < 10; place++)
textBox1.AppendText("Element" + place + " of the array contains " + a[place] + "\n");
}
private void btn_quit_Click(object sender, EventArgs e)
{
Close();
}
mydialogs kodu
class My_Dialogs
{
public static string InputBox(string promptText)
{
string default_value = "";
return InputBox("", promptText, ref default_value);
}
public static string InputBox(string title, string promptText)
{
string default_value = "";
return InputBox(title, promptText, ref default_value);
}
public static string InputBox(string title, string promptText, ref string value)
{
Form form = new Form();
Label label = new Label();
TextBox textBox = new TextBox();
Button buttonOk = new Button();
Button buttonCancel = new Button();
form.Text = title;
label.Text = promptText;
textBox.Text = value;
buttonOk.Text = "OK";
buttonCancel.Text = "Cancel";
buttonOk.DialogResult = DialogResult.OK;
buttonCancel.DialogResult = DialogResult.Cancel;
label.SetBounds(9, 20, 372, 13);
textBox.SetBounds(12, 36, 372, 20);
buttonOk.SetBounds(228, 72, 75, 23);
buttonCancel.SetBounds(309, 72, 75, 23);
label.AutoSize = true;
textBox.Anchor = textBox.Anchor | AnchorStyles.Right;
buttonOk.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
form.ClientSize = new Size(396, 107);
form.Controls.AddRange(new Control[] { label, textBox, buttonOk, buttonCancel });
form.ClientSize = new Size(Math.Max(300, label.Right + 10), form.ClientSize.Height);
form.FormBorderStyle = FormBorderStyle.FixedDialog;
form.StartPosition = FormStartPosition.CenterScreen;
form.MinimizeBox = false;
form.MaximizeBox = false;
form.AcceptButton = buttonOk;
form.CancelButton = buttonCancel;
if (form.ShowDialog() == DialogResult.Cancel)
{
textBox.Text = "";
}
return textBox.Text;
}
}
}
benim kodudur ////////////////// ////////////////////////////////////////////////// ////////
Dönüşüm işleminin başarılı olup olmadığını kontrol etmediniz. Yapar? Kodu ayıklayın ve ne olduğunu görün. –
"Girdi" bir tam sayıya ayrıştırılamıyor gibi görünüyor. Int32.TryParse() 'de bir kesme noktası ayarlayın ve giriş içeriğini değerlendirin. – derpirscher
kodunuz derleniyor mu? Ben endeksleyici 'out' değiştirici kullanamaz düşünüyorum düşünüyorum bir [yer] ' –