473,386 Members | 1,779 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,386 software developers and data experts.

Generic List

Hello,

I have a generic list named Rows:

Dim a As New Generic.List(Of Row)

Row is a structure which has 2 properties: Name and Content.

Is it possible, without a for loop, to find a Row in Rows which Name
is "Home" and get its content?

Thanks,

Miguel

Mar 12 '07 #1
3 2424
On Mar 12, 4:49 pm, "shapper" <mdmo...@gmail.comwrote:
Hello,

I have a generic list named Rows:

Dim a As New Generic.List(Of Row)

Row is a structure which has 2 properties: Name and Content.

Is it possible, without a for loop, to find a Row in Rows which Name
is "Home" and get its content?

Thanks,

Miguel
I think this is how you'd do it in C#:

Row rw = Rows.Find(delegate(Row aRow)
{
return (aRow.Name == "Home"));
}
);

string someContent = rw.Content;
Mar 12 '07 #2
On Mar 12, 5:21 pm, "mark4asp" <mark4...@gmail.comwrote:
On Mar 12, 4:49 pm, "shapper" <mdmo...@gmail.comwrote:
Hello,
I have a generic list named Rows:
Dim a As New Generic.List(Of Row)
Row is a structure which has 2 properties: Name and Content.
Is it possible, without a for loop, to find a Row in Rows which Name
is "Home" and get its content?
Thanks,
Miguel

I think this is how you'd do it in C#:

Row rw = Rows.Find(delegate(Row aRow)
{
return (aRow.Name == "Home"));
}
);

string someContent = rw.Content;
This is not working.

I tried to create a class as follows:

' BoxPredicates
Public Class BoxPredicates
Public Shared Function FindRowByName(ByVal row As BoxRows.Row, ByVal
rowName As String) As Boolean
Return String.Compare(row.Name, rowName)
End Function ' FindRowByName
End Class ' BoxPredicates

However, I have no been able to use this in List.Find.

Could someone, please, help me out?

Thanks,
Miguel

Mar 13 '07 #3
shapper schrieb:
Hello,

I have a generic list named Rows:

Dim a As New Generic.List(Of Row)

Row is a structure which has 2 properties: Name and Content.

Is it possible, without a for loop, to find a Row in Rows which Name
is "Home" and get its content?
Hi shapper,

you could use the Find method with a suitable predicate as in (here
strings, but could be your datatype Row):

Dim dinosaurs As New List(Of String)

dinosaurs.Add("Compsognathus")
dinosaurs.Add("Amargasaurus")
dinosaurs.Add("Oviraptor")
dinosaurs.Add("Velociraptor")
dinosaurs.Add("Deinonychus")
dinosaurs.Add("Dilophosaurus")
dinosaurs.Add("Gallimimus")
dinosaurs.Add("Triceratops")

Console.WriteLine(vbLf & _
"Equals: {0}", _
dinosaurs.Find(AddressOf Equals))
...

Private Shared Function Equals(ByVal s As String) _
As Boolean
If ("Velociraptor" = s) Then
Return True
Else
Return False
End If
End Function
But I doubt there is anything else happening than a for loop.

So, the first thing that comes to mind for this is a hashtable (generic:
Dictionary). Can you use that instead of a list? (The hashtable will NOT
keep the order of the items!)

If not, maybe you can derive from list and have a hashtable in your
class, which references the entries. You'll have to keep both list and
hashtable in sync though.

Hope this helps,

Cheers,

Roland
Mar 13 '07 #4

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

Similar topics

3
by: Abhi | last post by:
In the following hypothetical example I want to build a generic list of unique string items. How should I implement the pred function so that it returns true/false if target string exists in the...
8
by: JAL | last post by:
Here is my first attempt at a deterministic collection using Generics, apologies for C#. I will try to convert to C++/cli. using System; using System.Collections.Generic; using System.Text; ...
0
by: Wiktor Zychla [C# MVP] | last post by:
We do have generic classes, methods and delegates. My question is: what reason prevents us from having generic properties and indexers? // impossible public List<T> GetList<T> { get { ... }
0
by: crazyone | last post by:
I've got a gaming framework i'm building and i want to save myself the trouble of reading and writting the complete game data to a custom file and load/save it to an XML file but i'm getting...
3
by: Seth Gecko | last post by:
Hi I am working with generic lists of various objects and a control dealing with these lists. For instance: A parent form holds: dim Walls as List(Of wall) dim Segments as List(Of segment) ...
4
by: =?Utf-8?B?QkogU2FmZGll?= | last post by:
We have a class that has a public property that is of type List<T>. FXCop generates a DoNotExposeGenericLists error, indicating "System.Collections.Generic.List<Tis a generic collection designed...
1
by: Suds | last post by:
Hi, I'm having an issue with invoking a Generic method that takes Generic Arguments. My method signature is public void GenericMethodWithGenericArguments<E, V>(List<EtheFirstList,...
13
by: rkausch | last post by:
Hello everyone, I'm writing because I'm frustrated with the implementation of C#'s generics, and need a workaround. I come from a Java background, and am currently writing a portion of an...
5
by: Jon Slaughter | last post by:
I have some code like if (val.GetType().Name == typeof(List<>).Name) { } which lets me determine if val is a generic list(I've already taken care of the non-generic part but I'd rather be...
2
by: SimonDotException | last post by:
I am trying to use reflection in a property of a base type to inspect the properties of an instance of a type which is derived from that base type, when the properties can themselves be instances of...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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
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...

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.