.net - Compare Different Generic Lists?

Mar 2, 2011

I have a method where I'm taking a generic object and using TypeOf to check what has been passed through. Now I would like to pass it a List(Of T) (T being anything) and no matter what T is I'd like to do the same thing to this list. I tried the following:

public sub foo(ByVal obj As Object)
if TypeOf obj Is List(Of Object) Then
'do stuff
end if
end sub

but this doesn't seem to work if I pass it List(Of String), say. I suppose that List(Of Object) and List(Of String) are being treated as different objects, but I thought that since String is an object, the comparision might work.

Now I realise that this is as ugly as sin and I'm better off overloading the method to take List(Of T) as its parameter, but I'm mostly asking out of curiosity: is there a way of comparing the types List(Of Object1) and List(Of Object2) and getting a positive result, since they are both just List(Of T)?

View 3 Replies


ADVERTISEMENT

Make Passing Generic Lists

May 6, 2009

I have a utility class that takes a generic list as a parameter.Code looks like:

Function DoStuff(collection as Object, elt as Object)
...
collection.Add(elt)

[code]....

View 3 Replies

Compare Differences Between Lists?

Feb 17, 2011

Compare differences between lists?I have two sets of lists below[code]...

View 1 Replies

[2005] How To Compare Two Lists

Jan 22, 2009

Im trying to compare two lists,to find out how which items occur in both lists. I also want to test for duplication within a list.Now, the obvious way is a loop/compare which works fine for a low number of items. Beyond 10000 items, things slow down much more than a factor of 10.

Dim List1 As New List(Of String)
Dim List2 As New List(Of String)
Dim List3 As New List(Of String)

[code]....

View 3 Replies

.net - Comparing Two Generic Lists On A Specific Property?

Jul 9, 2010

I'm using VB.NET with .NET 2.0. I have two lists, and I want to compare the lists on a specific property in the object, not the object as a whole, and create a new list that contains objects that are in one list, but not the other.

myList1.Add(New Customer(1,"John","Doe")
myList1.Add(New Customer(2,"Jane","Doe")
myList2.Add(New Customer(1,"","")

Result in the above example would contain one customer, Jane Doe, because the identifier 2 wasn't in the second list.How can you compare these two List<T> or any IEnumerable<T> in .NET 2.0 (lacking LINQ)?

View 2 Replies

VS 2005 - Generic Lists Of Unknown Type

Sep 14, 2009

I have recently moved from VB 2003 to VB 2005. While I am finding a lot of the new features quite useful, I am having trouble with List (of T). I want to be able to do something like this

Function GetList(MyObjectType as Type) as datatable
Dim list as new List(of MyObjectType)
End Function
Function GetList(MyObjectType as String) as datatable
Dim list as new List(of GetType(MyObjectType))
End Function

VB 2005 does not allow me to do this at all. Must the "type of" be srongly declared at all times? Can't this be done dynamically?

View 2 Replies

Arrays - Compare Two Lists 2D And Determine

May 2, 2012

I declare my 2D lists:

Dim _invoiceitems As New List(Of List(Of String))
Dim _dbitems As New List(Of List(Of String))

Each List is filled like this: Example Code To fill:

_invoiceitems.Add(New List(Of String))
_invoiceitems(0).Add("Code #")
_invoiceitems(0).Add("Quantity")

Well, now i need a third list called (_changesitems) Note that this result with the differences: be the result of subtraction of quantities if this is found (dbitems - invoiceitems).

View 1 Replies

C# - .NET Generics - Compare Two Lists And Filter?

Jun 19, 2011

I have two generic lists of type T. Both lists contain same type, and I'd like to create a third list (or a filtered version of list 2) based on the items in list two that do not exist in List 1, based on the ID of each item.Each list holds a "Package" object, which has an ID property.Right now I mocked up the code using For Each loops, which I know is horrible (the Big O is constant time) so I'd like a more efficent method. this code is in VB per project requirments, but I prefer C# - so either code sample would work for me.

Private Sub RemoveStockPackagesFromSelection()
Dim p As Package
Dim packageList As List(Of Package) = New List(Of Package)

[code]....

View 5 Replies

Generic Lists Copying References Rather Than Creating A CopiedList

Mar 8, 2010

I was developing a small function when trying to run an enumerator across a list and then carry out some action. (Below is an idea of what I was trying to do. When trying to remove I got a "Collection cannot be modified" which after I had actually woken up I realised that tempList must have just been assigned myLists reference rather than a copy of myLists. After that I tried to find a way to say

[Code]...

View 4 Replies

Comparison - 4 String Lists - Compare The Contents Of The Input List - Containing Words

May 31, 2009

I have 4 string lists as follows

Dim input_list As New List(Of String) Dim input_POS As New List(Of String) Dim trigger_list As New List(Of String) Dim trigger_POS As New List(Of String)

I want to compare the contents of the input list (containing words (e.g., want, the) etc. to the ones of the trigger list (containign again words) and if a same entry (i.e. word) get the POS for both input word and trigger word from the relevant lists and put them into a property list. For example

input list (want, the, right)trigger list(want, there, wait)input list POS (verb, article, adjective)trigger list POS (verb, pronoun, verb)

Output property list (want:verb, want:verb) (only want is common between input and trigger list). Then I need to conduct a test between the two property items for similarites. If they are exactly the same, the code should output a confirmation "i.e., Yes" into a textbox. If not the code should output a "No" plus the contents of the property list into a textbox.

View 6 Replies

Sorting 2 Lists Based On Only One Of The Lists?

Apr 1, 2011

I have two lists. One list is a list of names, the other list is a list of how many times each name is found in the first list noted in the database

so...
Nick
John
Jim
Jack

is the firs tlist

10
13
13
2

is the second list. Nick had 10, john 13 and so on.I want to sort the second list from large to small, but have the index for the first list still linked to the correct amount of calls.i do it this way so I can

for x = 0 to num_of_names
string = lst_name(x) & "-" & lst_count(x)
next x

View 3 Replies

Is There A Concept Of "Generic Structure" Similar To Generic Collections, Generic Classes

Dec 16, 2009

We have migrated our Vb6 application to VB.NET using a third party tool. Now we are in a process of Refactoring and introducing object oriented concepts in the application.

In VB6, we were using structures in many places. As a part of introducing object oriented programming,

1. is it a good idea of changing all Structures to Classes? or Is there a concept of "Generic Structure" similar to Generic collections, Generic classes?

2. Can some one guide me any source containing guide lines or best practices for applications that are migrated to VB.NET from VB6 and implementing object oriented programmaing.

View 3 Replies

.net - Can A Generic Version Of A Derived Class Override A Base Method Using The Generic Type

Apr 13, 2012

Consider:

Public MustInherit Class Column
Public ReadOnly Property ReturnSomethingUseful() As Object
Get
'return something useful

[code]....

But this gives the following error:

Public Overrides Function ParseValue(sValue As String) As Boolean'
cannot override 'Public Overridable Function ParseValue(sValue As String) As Object'
because they differ by their return types.

I accept that you can't do this, but I'd like to be able to preserve the semantics of what I'm. trying to do, which is to have an untyped version that deals with Object, but a typed version in derived classes that knows about the specific type T.

View 2 Replies

.net - Determining A Generic Type At Runtime In Non-Generic Class

Aug 14, 2010

I have a Journal that records entries for different types: Journal(Of ParentT)

[Code]....

View 2 Replies

Construct A Generic Interface Class With Generic Functions

Nov 25, 2011

I am trying to construct a generic interface class with generic functions. My goal was to use this to implement multiple worker classes for database interaction that have the same basic functionality. Each class will deal with different object for example, category, product or supplier but unless the the functions in the interface are generic that this won't work.This is the interface code that I have but I don't know if I have done it correctly. [code]

View 2 Replies

Know If An Array Of Lists Contains Similar Items (similar Lists)?

May 20, 2010

I know how to check whether an item exists in a list using (MyList.Contains), But I do not know how to check the whole list. For example (use one button and one richtextbox):

[Code]...

View 14 Replies

.net - Creating A Generic List Of A Generic Type

Jun 30, 2011

I am trying to create a list of a generic type in vb.net 2.0 framework.
This is the generic type definition:

Public Class GenericParamMap(Of T)
Public Sub New(ByVal pParamName As String, ByVal pPropValue As T)
mParamName = pParamName

[Code]....

The compiler does not allow a "T" in the method's parameter because it's not defined, but I'm not sure how or where to define it. I thought it was okay to have a generic method definition.

View 2 Replies

Generic Cannot Instantiate Instance Of The Generic Type With New?

Feb 8, 2012

I am trying to write a generic method, to avoid code duplication, which will create or activate a Form as an MDI children, based on its type. But I have to lines in error (see comments).

[Code]...

View 4 Replies

Compare Date - Compare Textbox1 And Textbox2 Text

Mar 3, 2010

I have two textbox in my application.

Textbox1.Text="19-Jan-2010"

Textbox2.Text="Jan 2010"

May I know how can I compare that Textbox1 and Textbox2 text is within same month and same year?

View 1 Replies

VS 2008 Accessing Something With A Generic Generic?

Jun 19, 2012

If i have an object that implements an interface (and don't know the exact object) i can call a sub (DoSomething) by going:

vb
Dim iObj = trycast(something, iInterface)
if iObj isnot nothing then
iObj.DoSomething()
end if

How can I do this for a Generic? such as...

vb
Public Class TestClass(of T)
Public sub DoSomething()
....
end class

View 2 Replies

Multithreading - Modify A Generic Invoke Method To A Generic BeginInvoke Method?

Oct 7, 2010

I have been using a pretty slick generic invoke method for UI updating from background threads. I forget where I copied it from (converted it to VB.NET from C#), but here it is: Public Sub InvokeControl(Of T As Control)(ByVal Control As t, ByVal Action As Action(Of t))

[Code]....

View 1 Replies

Compare Version Between Host And Client Download The File If Compare Version Not Same In .net?

May 20, 2011

they need to make some compare version between host version and client version.. and each 1 version different will download the file to the client..[URL]..with both example, how can i make a program in VB.NET just like i said just now?

View 15 Replies

Overload Operator In Generic Class With Generic Interface Of Super Class And Inherit Class?

Jan 21, 2010

I can do this without problem.

Class A
End Class
Class B : Inherit A
End Class
Dim Obj1 As A = New B

View 4 Replies

For Each Loop - Two Lists?

Jul 24, 2010

I would like to loop through two lists using a For each loop.
dim data as list(of pointpairlist)
For each recLine in records
For Each chan In recLine.channels and d in data
d.add( func(chan) )
Next
next

Note: each record line has one sample from each channel recorded. i.e. each record line is a slice of a 32 sensor recordings. I want to build up a x,y list of data points for each channel (the x axis is common to all channels). Is there some way to do it similar to what I have above (avoiding indexing variables).

View 2 Replies

Passing Lists From WCF To WCF In VB?

May 13, 2011

I'm trying to populate one list from another. I would think this code should work, but at the end of the day I get a list of identical items.

Public Sub WriteDatFile(ByRef lstReasons As System.Collections.Generic.List(Of LetterReason))
Dim tmplstReason As New TCPService.LetterReason

[Code]....

View 2 Replies

VB Lists And Calculations?

Jun 6, 2011

I'm very new to programing and am having problems trying to perform some calculations with a list. I have read in an array into a list with a count attached to each item example: "xxxxxx(intcount)". What I'm trying to do it use two xxxxxx(intcount)'s at xxxxxx(intcount+5) and xxxxxx(intcount+25) and use these two variables to calculate yyyyyy(intcount) but it isn't working. I understand this may be a stupid question but could someone please point me in the right direction.

View 6 Replies

Display The Lists Of Costs ?

Mar 20, 2011

Ok this is a hw assignment like always....just not sure on how to do the math on this form...the constants are declared for the registration fees and i did the same for the required days at each work shop i just need to find a way to multiply the days required at each workshop by the lodging fees. but i also need to display the lists of costs so its pretty complicated.

View 6 Replies

Comparing 2 Lists Name And Price?

Dec 17, 2009

I'm creating <!-- /* Font Definitions */ @font-face {font-family:"Cambria Math"; panose-1:2 4 5 3 5 4 6 3 2 4; mso-font-charset:1; mso-generic-font-family:roman; mso-font-format:other; mso-font-pitch:variable; mso-font-signature:0 0 0 0 0 0;} @font-face {font-

[code].....

View 2 Replies

FluentValidation With Lists Of Objects?

May 31, 2012

Right now I have a viewmodel that contains three lists of inputs; textboxinput, dropdownlistinput, and checkboxinput. Each of these lists is a list of input objects, which contain four values; paramenums, paramname, paramtype, and value. I am using these input lists to generate a variable number of fields on a form dependent on how many objects each list contains.

My current problem is that I'm not sure how to validate the variables in the list objects with fluent validation. I know how the behavior of each list should behave with regards to returning Nothing, but I don't know how to code that behavior with FluentValidation.

[Code]...

The thing I want to currently do is confirm that in every object in each of my lists, they all have a value attribute that isn't nothing. Can I do this by validating the input model? Right now, the code works at confirming that the list itself isn't null, but the objects in the list can still contain all null values. Is there a trivial way to do this? Alternatively, should I have set my code up differently?

View 1 Replies

Grab, And Lists All Into A Listbox?

Aug 27, 2011

<a href="http://www.websitename.com/Name" data-hovercard="/ajax/hovercard/user.php?id=100054545">Name</a>

how to grab, and lists all into a listbox?

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved