473,395 Members | 1,791 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Filter an array with LINQ in VB

Hello,
I've heard that LINQ can do pretty much the same thing I could do if I
could run an SQL query on my collection. I'd like to do something like
this:

Let's say I have and array of object of type TypeOne
The TypeOne has a property called id of type string
I have an array that contain thousands of string that represent ids of
TypeOne object.
I'd like to filter my array so that only those that their id property
match with one of those in my array of string be returned.

At first, I tried doing something like :

dim filteredArray as TypeOne()
filteredArray = From a in ArrayOfOnes Join i in ArrayOfIDs On a.id = i

but I have not found a way to return an array of TypeOne. I get a cast
exception saying I cannot cast a join iterator to a TypeOne()

I tried
filteredArray = From a in ArrayOfOnes From i in ArrayOfIDs Where a.id
= i

I get another cast error.

As you can probably see, I'm a real beginner with LINQ but I'd really
like to learn it. Is there a way to filter my array and get back a
strongly typed array with LINQ?
Feb 15 '08 #1
1 2818
Just in case someone wonder I would do it like this in SQL
SELECT TypeOnes.* FROM TypeOneCollection INNER JOIN IDs ON IDs.theID =
TypeOnes.ID
Feb 15 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: pinkfloydfan | last post by:
Hi there I have a C# program that produces a lot of data that I currently store in a jagged array and I have a couple of questions that I was hoping someone might shed some light on for me...
6
by: Plissskin | last post by:
I need to create an "ad-hoc" filtering page in a web app we are building. The page would display a number of drop down lists, text boxes, and radio lists and allow the user to select (enter) some...
4
by: Rich P | last post by:
Maybe you could try using a query as the recordsource for your subforms and for the criteria field in the query you could use a Form parameter. This way - instead of using the form filter property...
0
by: shapper | last post by:
Hello, I have the following Linq query: viewData.PostsPapers = (from p in database.Posts select new PostPaper { Post = p, Tags = string.Join(", ", (from pt in database.PostsTags
3
by: raylopez99 | last post by:
This is an example of using multiple comparison criteria for IComparer/ Compare/CompareTo for List<and Array. Adapted from David Hayden's tutorial found on the net, but he used ArrayList so the...
4
by: raylopez99 | last post by:
I would like to know if there's a quick "Linq" way to find the index of an array having a particular value. I can do this the long way by sequential iteration, but would like to know if there's a...
2
by: shapper | last post by:
Hello, I have the following class ( Level is just a simple enumeration ): public class Theme { public Subject Subject { get; set; } public List<LevelLevels { get; set; } public string Note {...
2
by: Duggi | last post by:
Hi I have a dataview. I would like to apply a filter on the dataview on a column with datatype system.string. I have filter with wild char *. I need to support wild chars * and ? in...
5
aas4mis
by: aas4mis | last post by:
I haven't had much luck with specific controls, their properties and loops in the past. I thought I would share this tidbit of code, feel free to modify/modularize in any way to suit your needs. This...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.