Simplify code

Peter Volz 1,295 Reputation points
2024-03-04T08:36:59.95+00:00

Hello,

Here's the working code:

Dim MyString(MyValues.Count - 1) As String
For MyLoop As Integer = 0 To MyValues.Count - 1
  MyString(MyLoop) = MyValues.Item(MyLoop).Text
Next
Return MyString

I'm courious to know if there's a way to simplify this code and return the whole members of MyValues.Text as string array at once? (like using Linq)

Thanks for help :)

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,839 questions
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,714 questions
0 comments No comments
{count} votes

Accepted answer
  1. Jiachen Li-MSFT 31,011 Reputation points Microsoft Vendor
    2024-03-04T09:51:58.0533333+00:00

    Hi @Peter Volz ,

    Try the following code using Linq to get the string array.

    Dim MyString() As String = MyValues.Select(Function(item) item.Text).ToArray()
    Return MyString
    
    

    Best Regards.

    Jiachen Li


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.