-1

I have this code :

    for(int i=0;i<???;i++)
    {    
        ...
    }
    tb.SetWidths(new int[] { 50, 50, 50,.... });

The problem is:

  • The amout of array elemens must be equal to "i"
  • I also want to set the value to all these elements to 50

How can i do that?

Tb is an object from itextsharp, i'm using it to draw tables on pdf files

Michail Michailidis
  • 11,792
  • 6
  • 63
  • 106
Liev04
  • 401
  • 1
  • 5
  • 13

2 Answers2

4

I guess something like that would work for you? (https://stackoverflow.com/a/34379619/986160)

if count is random you can do:

Random rand = new Random();
int count = rand.Next(1, 101); // creates a number between 1 and 100

( 50 is the fixed value for all 'count' elements)

int[] array = Enumerable
              .Repeat(50, count)
              .ToArray();

then you can do:

 tb.SetWidths(array);
Community
  • 1
  • 1
Michail Michailidis
  • 11,792
  • 6
  • 63
  • 106
1

It seems like you've put little to no effort into this exercise.

By simply Googling "c# define array of size" I found the following code:

 int i = random number;
 int[] myArray = new int [i];

Next, in order to populate the array with a certain integer, you simply loop through it:

    for(int x = 0; x < myArray.Length; x++){
        myArray[x] = 50;
    }
AndreiROM
  • 123
  • 1
  • 6