Solved

Linq to List of string not working

Posted on 2012-03-22
3
345 Views
Last Modified: 2012-03-22
hello ee,

i have this:    dim q = (From x in myTable Select x.Field(Of String)("CompanyNo")).Distinct()

wich reuslt as:

"01"
"02"
"00"

I have :   Dim list as new List(Of String)

Im trying:       list = q  
to fill my List with "01" "02" "00"

but i have error

how can I fill my list with q ?
0
Comment
Question by:PhilippeRenaud
3 Comments
 
LVL 38

Accepted Solution

by:
PaulHews earned 400 total points
ID: 37753310
Have you tried:

list = q.ToList()
0
 
LVL 74

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 100 total points
ID: 37753365
Right (with respect to PaulHews). The "thing" returned by your query is defined by function you last called against the query (I'm speaking of Distinct in this case), or the query itself if you don't execute any function against it. The Distinct method returns back an IEnumerable(Of T), which is not a List(Of T). A IEnumerable(Of T) can be loaded or turned into a List(Of T), but it is not the same as a List(Of T). You can use the aforementioned ToList extension method to convert the IEnumerable(Of T) you get back from Distinct into a List(Of T).

* I'm using the generic terms "Of T". You are using String, so substitute String for T in the above description.
0
 
LVL 1

Author Closing Comment

by:PhilippeRenaud
ID: 37753376
thanks, actually I tried but went to fast and my toList() was placed at the wrong place.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now