-
Jan 31st, 2013, 01:51 AM
#1
Thread Starter
PowerPoster
[RESOLVED] How to loop through anonymous type array
Hi Guys,
I'm trying to get distinct rowsfrom a datatable using LINQ.
Code:
Dim categories = dt.AsEnumerable().[Select](Function(row) New With { _
Key .Id = row.Field(Of UInt32)("ID"), _
Key .Name = row.Field(Of String)("name") _
}).Distinct().ToArray
This does the job. I'm not sure how to loop through the categories array now to get the ID and Name values. Please advise me
-
Jan 31st, 2013, 02:04 AM
#2
Thread Starter
PowerPoster
Re: How to loop through anonymous type array
no worries. I got it.
For Each cat In categories
Dim catID As UInt32 = cat.Id
Dim catname As String = cat.Name
Next
-
Jan 31st, 2013, 02:18 AM
#3
Frenzied Member
Re: [RESOLVED] How to loop through anonymous type array
I think you need to create a structure and use a function. i am assuming you are getting employee information so i use the name employee for this example, you can follow the idea and use a more appropriate name
Public Structure Employee
Dim id as integer
Dim name as String
End Structure
Then use a function
Public Function GetEmployeeInfo() as Employee()
Dim categories = dt.AsEnumerable().[Select](Function(row) New With { _
Key .Id = row.Field(Of UInt32)("ID"), _
Key .Name = row.Field(Of String)("name") _
}).Distinct().ToArray
Return categories
End function
then you can use
employee.id
employee.name
Hope this helps
-
Jan 31st, 2013, 02:19 AM
#4
Frenzied Member
Re: [RESOLVED] How to loop through anonymous type array
or you can do it the way you discovered lol
-
Jan 31st, 2013, 03:30 AM
#5
Thread Starter
PowerPoster
Re: [RESOLVED] How to loop through anonymous type array
thanks anyway billboy
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|