Home > Net >  How to create an array with size that is passed through the textbox?
How to create an array with size that is passed through the textbox?

Time:11-14

How to create an array with size that is passed through the textbox? enter image description here

int massivSize = int.Parse(textBox1.Text);
int odnMassiv = new int[massivSize];

CodePudding user response:

use int[] or var in declaration, like this:

int massivSize = int.Parse(textBox1.Text);
var odnMassiv = new int[massivSize]; 

or

int massivSize = int.Parse(textBox1.Text);
int[] odnMassiv = new int[massivSize];

CodePudding user response:

You have typed:. int odnMassive = ...

While it should be:. int[] odnMassive =.

Or you can use var instead, like: var odnMassive = new int[massiveSize]; I find this more useful in most cases (except when the data type is unknown)

  • Related