Я беру динамический массив как
I put some values in it in run time, but if user put less then 10 values like if user put 5 values in it instead of 10. After that when i display the array first it's show the five value and after that start displaying 0 0 0 0 0. I just want to know is there any method to get rid of using dynamic array in c#?
Что я уже пробовал:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace hassan_algo { public partial class Input_Form : Form { int min = 0, max = 0, step = 0; double[] array = new double[10]; /* double[] array = { };//notice I did not declare a size for the array List<double> tmpList = new List<double>(); */ int i = 0; public Input_Form() { InitializeComponent(); } private void textBox2_TextChanged(object sender, EventArgs e) { } private void exit_Click(object sender, EventArgs e) { Environment.Exit(0); } private void clear_Click(object sender, EventArgs e) { textbox_min.Clear(); textbox_max.Clear(); textbox_step.Clear(); textbox_min.Focus(); } private void execute_Click(object sender, EventArgs e) { calculat(); } public int calculat() { if (String.IsNullOrEmpty(textbox_min.Text) || String.IsNullOrWhiteSpace(textbox_max.Text) || String.IsNullOrWhiteSpace(textbox_step.Text)) { MessageBox.Show("Please fill the textbox"); } else { min = Convert.ToInt32(textbox_min.Text); max = Convert.ToInt32(textbox_max.Text); step = Convert.ToInt32(textbox_step.Text); while (min <= max) { array[i] = min; min = min + step; i++; } string output = string.Empty; foreach (var item in array) { output += item + "\n"; } MessageBox.Show(output); } return 0; } } }