473,796 Members | 2,697 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2480
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(deleg ate(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(deleg ate(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(B yVal 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.WriteLi ne(vbLf & _
"Equals: {0}", _
dinosaurs.Find( AddressOf Equals))
...

Private Shared Function Equals(ByVal s As String) _
As Boolean
If ("Velocirapt or" = 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
15183
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 generic list...is not clear to me. Any suggestions? System.Collections.Generic.List<string> list = new System.Collections.Generic.List<string>(); foreach(string s in myAnotherArray)
8
1834
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; namespace DeterminedGenericCollection { // I got tired of copy and pasting IDisposable
0
6855
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
5930
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 problem serializing my stuff to XML when it comes to collections. I'm currently using .net2 with generic lists to prevent users putting all sorts of stuff in the arrays (Although im sure i'll be the only user of the classes but not the game, anyway)....
3
2262
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) The parent form have a custom control, which have a public sub looking
4
7569
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 for performance not inheritance and, therefore, does not contain any virtual members. The following generic collections are designed for inheritance and should be exposed instead of System.Collections.Generic.List<T>. *...
1
2785
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, List<VtheSecondList); I pass the name of the method, the arguments for the "GenericMethodWithGenericArguments" to another method, which is supposed to invoke this method using the Invoke method in the MethodInfo class. My process of invocation is as follows
13
3838
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 application that needs implementations in both Java and C#. I have the Java side done, and it works fantastic, and the C# side is nearly there. The problem I'm running into has to do with the differences in implementations of Generics between the two...
5
3638
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 able to compare them like if (val is List<>) but this obviously doesn't work. (and I can't code it for every
2
4186
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 types derived from that base type, or arrays or generic collections of instances of types derived from that base type. All is well until I come to the properties which are generic collections, I don't seem to be able to find an elegant way of...
0
9533
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10461
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10190
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10019
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9057
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6796
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5579
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4122
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2928
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.