0

Like with initialization: We take like:

 Dim a() as integer = {1,2,4,6}

And if i want to print the array list it will be 1 , 2 ,4,6 as output But how can i take any value i.e n value to print n values as output.

1
  • If you need a different array, then: Dim n As Integer = 3 followed by Dim b() As Integer = a.Take(n).ToArray Commented Apr 12, 2021 at 12:42

1 Answer 1

0

Seems to me your best bet will be to add n elements from the array to a second array and print that instead:

Dim a() as integer = {1, 2, 3, 4, 6}

Dim b as new list(of integer)
' Where n is the total number of elements you want to print.
For counter As integer = 0 To n
    b.Add(a(counter))
Next

PrintItems(b)

I haven't worked in VB for nearly 10 years so apologies if my code isn't 100% correct.

Sign up to request clarification or add additional context in comments.

3 Comments

What is the use of the List here? You could just, e.g.,: for each v as Integer In a.Skip(1).Take(3) Console.WriteLine(v) next to print out elements from index 1 to 3. BTW, to initialize a List with the elements of a, just Dim b As New List(Of Integer)(a)
I used a list here because I'm actually an idiot lol I forgot how to create an empty array... I usually use lists in my code anyway
Will wait on feedback from OP first... in the meantime please don't report my comments D: I'm so close to 10k although it's taken a decade to get this far lol

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.