Finding Equality In Items In Two Lists Of Differing Types?

Jun 9, 2009

I have two objects that are derived from same the base class. ets say ObjA is the base class, and ClassB and ClassC inherits ObjA. f I have a dim lst1 as List(Of ClassB) im list2 as List(Of ClassA)nd and I want to check for the existence of something being in lst1 that it is in list2, now I am only interested in comparing against one key bit of information that it is declared in the base class and is a string. How can I iterate through the lst1 comparing against list2? I thought I could I overload/override the Equals method but I am having no joy for either of the classes and say some thing similar to

Public Overloads Overrides Function Equals(ByVal obj As Object) As Boolean
Dim temp As ClassA = TryCast(obj, ClassA)
If temp.Id = Me.Id Then

[code].....

View 1 Replies


ADVERTISEMENT

.net - Using Child Classes Polymorphically With Differing Return Types?

Apr 10, 2012

I have two Parser classes that inherit from a base class, BaseParser. I want to use either class as a parameter in another Monitor class. The Parser classes, CS600 and TCH600, both have two properties, RawDataList and SummaryDataList. The CS600 class's RawDataList returns a List(of CS600Data); the TCH600 RawDataList returns a List(of TCH600Data). The SummaryDataList returns similar classes in each Parser class. CS600Data and TCH600Data derive from a base class, BaseData.BaseParser also has RawDataList (List(of BaseData)) and SummaryDataList (List(of BaseSummaryData))The Monitor class has a private field, _thisParser which can be either of the two concrete Parsers above. I want to be able to call and use RawDataList and SummaryDataList of _thisParser within Monitor class, but when I construct the concrete Parser classes, Visual Studio notes that the RawDataList property of CS600 cannot override the RawDataList property of the BaseParser because they differ in their return types.

I thought that since CS600Data derived from BaseData (but also adds some new properties of its own) that I could use CS600Data wherever I use BaseData. What am I misunderstanding? How can I correctly construct these classes?

Public MustInherit Class BaseParser
Protected _rawDataList As List(Of RawGasData.BaseData)
Public MustOverride ReadOnly Property RawDataList() As List(Of RawGasData.BaseData)

[code]....

View 1 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

Asp.net - Finding A .net Code To Add Existing Buttons/text Boxes/drop Down Lists, Etc To A Container Or Holder?

Jun 17, 2012

I'm using vb.net. Basically, I have a drop down list, text box and a submit button. You choose a movie director from a drop down list, then type in a movie, click button and it adds the data to my database.There's another button which hides/shows drop down list, text box and submit button using Visible = True and Visible = False, but what I don't like about it is when it hides the things I said before, it leaves some white/empty space like if they are still there, but not visible.Is there anyway to put some kind of holder/container and place a button which when clicked could add my drop down list, text box and submit buttons to that place?

View 1 Replies

C# - Arbitrary Precison Floating Types In .net : Finding Library That Allows That?

Oct 21, 2009

I need to do maths on both floats and integers with much bigger accuracies and magnitudes than offered both by int/float/double in .net. I recall there was something like that for c/c++.

View 2 Replies

Selecting Items At Same Index In Multiple Lists?

Apr 6, 2012

I am working on a project for software engineering where we are trying to create a warehouse inventory system. I have created an inventory page where I can add/delete/search for an item as well as access invoices and reorder items... i am struggling on the delete item part. I have my design set up where there are four different lists on my page. One for name, one for serial number, one for RFID number and one for amount in stock. I want to be able to select an item by name and its information in serial number, rfid, and amount also select and have no idea how to go about this..I wanted to use four different lists because I need to be able to delete an item from the list and it remove just one from that stock and not the entire item unless there is only one of that item left in stock.

for my inventory page

Public Class InventoryDepartment
Private Sub InventoryDepartment_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

[Code]....

View 14 Replies

Use LINQ To Find Complex Combinations Of Items In Two Lists?

Jun 28, 2010

This question is very similar to a previous question of mine, Use LINQ to count the number of combinations existing in two lists, except with some further twists.

I have a list of CartItems that can receive a discount based on the items specified in the list of DiscountItems. I need to be able to pull out the items in the Cart that can receive a discount and apply the appropriate discount specfied in the DiscountItem. The discount is only applied for each combination that exists. Here's what the two lists might look like to before the discount is applied[code]...

View 3 Replies

VS 2010 - Multiple ComboBoxes And Dropdown Lists With Different Items

Jul 16, 2010

I have multiple combox boxes,
A B C
Combobox B has items Fruit, Veg, Dairy
Combobox C needs to contain 3 list and depending on what value is selected in Combo Box B.

For example,
If I select Veg in Combo Box B, I would like to have a drop down list containing "tomatoes, lettuce, onion,..........."
If I select Dairy in Combo Box B, I would like to have a drop down list containing "Milk, Cheese...................."

View 8 Replies

Generics - List(Of T) - Use It To Hold Items Of Several Types?

Oct 3, 2009

Assuming a base type of "Message"...

[Code]...

I would like to have one collection of Message objects which can be either PhoneMessages or MailMessages, so that I can iterate through the list and deal with each message based on what type it happens to be.

Attempting just to use .Add() fails, saying that I can't add an item of type PhoneMessage to a List(Of Message). Is there some elegant way to accomplish what I'm trying to do? I had thought I could accomplish this with generics, but I think there's a gap in my understanding. If it can be accomplished in .NET 2.0, that would be ideal.

View 4 Replies

Link :: Excluding Items From Different List Types?

May 18, 2009

Is there any way to select items in a list that aren't contained in another? For example:list1 = From t In list1 Where Not list2.Contains(t.column1)That gives me the error:Value of type 'Integer' cannot be converted to '<anonymous type>'which makes sense, since list2.Contains is expecting the same type as list2. However, the list types are different. I want only to select based on column comparisons.

View 3 Replies

Finding Checked Items From ListView Control?

Mar 13, 2012

I am using ListView Control which CheckBoxes property of the control is set to true..when the from is loaded then all ordernos are loaded into the listview. when i select the orderno then enter contain of the selected orderno to displayed in datagridview control. now i want select 4 order nos and want to display all contain of 4 selected ordernos how find out which orderno is selected through loop and in which even i have to place.

View 1 Replies

Listbox Items Colour - Two Types Of Items Populating In A Listbox (checked Listbox)

Apr 28, 2009

I am using VB.NET (version 2008). I have two types of items populating in a listbox (checked listbox). For example: lets say one is type "A" and other is "Type B". Their names maybe same so if the user sees those items in listbox then he won;t be able to determine their type until he click on them and checks out its properties. I wanted that I add each item to listbox and colour them so that blue for example means type "A" is there and red means the other. So this way I will be able to know at a glance that how many item of what type is present. I guess it may not be possible to do that in a standard checkedlistbox. I am also using component factory's krypton controls which enhance the gui of an application. But I dunno if I can progress using that.

View 5 Replies

Finding Listbox Index Items And Proceed With Command

May 19, 2009

i'm having a little trouble with a listbox. [Code]. i want the button command to run through the listbox items and proceed with given command. it's not listbox1.items.indexof(#), it's something else i'm missing.

View 2 Replies

How To Do Equality Testing

Jan 18, 2012

I have a Do loop that I want to exit once it goes through without making any changes to an object I created. I figured the best way to do this was to create a temporary copy of the object at the beginning of the loop and then compare that to the actual object at the end of the loop to determine whether any changes were made to it. The problem occurs when variables are accessed and copied by reference. I have tried to use some of the methods such as .Clone and .Equals (maybe I shouldn't be using these, but I didn't see any better built-in methods), but I seem to be doing some stuff wrong. Can somebody give me an example of a good way to copy an object for later equality testing, and how to do the equality testing?

View 5 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

Asp.net - Checking The Equality Of Two Doubles In .NET?

Aug 5, 2010

I've got a heavily used web application that, for the first time in 2 years, failed doing an equality check on two doubles using the equality function a colleague said he'd also been using for years. The goal of the function I'm about to paste in here is to compare two double values to 4 digits of precision and return the comparison results. For the sake of illustration, my values are:

Dim double1 As Double = 0.14625000000000002 ' The result of a calculation
Dim double2 As Double = 0.14625 ' A value that was looked up in a DB

If I pass them into this function:

Public Shared Function AreEqual(ByVal double1 As Double, ByVal double2 As Double) As Boolean
Return (CType(double1 * 10000, Long) = CType(double2 * 10000, Long))
End Function

the comparison fails. After the multiplication and cast to Long, the comparison ends up being:

Return 1463 = 1462

I'm kind of answering my own question here, but I can see that double1 is within the precision of a double (17 digits) and the cast is working correctly. My first real question is: If I change the line above to the following, why does it work correctly (returns True)?

Return (CType(CType(double1, Decimal) * 10000, Long) = _
CType(CType(double2, Decimal) * 10000, Long))

Doesn't Decimal have even more precision, thus the cast to Long should still be 1463, and the comparison return False? I think I'm having a brain fart on this stuff...Secondly, if one were to change this function to make the comparison I'm looking for more accurate or less error prone, would you recommend changing it to something much simpler? For example:

Return (Math.Abs(double1 - double2) < 0.0001)

Would I be to try something like:

Return (double1.ToString("N5").Equals(double2.ToString("N5")))

View 3 Replies

Compare Strings For Equality?

Jul 22, 2009

I have a Label and a textbox that both contain strings. I want to compare the two strings like this:

If TextBox5.Text = Label18.Text Then
Label4.Text = "CLOSED"
Else
Label4.Text = "OPEN"
End If

Something in there is not working however. Has anyone done something similar?

View 21 Replies

.net - Compare Two Like Objects To Verify Equality?

Jan 17, 2012

I am attempting to compare a bitwise clone object to its parent to check for changes using:

If Not objCP.Equals(objCPClone) Then
'do something
End If

and it always compares as not equal even immediately after creating the clone. How should they be compared to check for changes?

View 2 Replies

If Statement - Testing Multiple Values For Equality?

Mar 26, 2009

How do you test multiple values for equality in one line?
Basically I want to do
if (val1 == val2 == val3 == ... valN)
but in VB.Net.

View 3 Replies

Lamdba Expression, Use Assignment Operator Instead Of Equality?

Oct 27, 2010

I have a method that takes an System.Action, this is what I'm trying to feed it:Function() Me._existingImports = Me.GetImportedAds()

The thing is that it complains about the = sign since it thinks I'm trying to do a comparison, which I'm not. I want to assign the Me._existingImports the value of Me.GetImportedAds(), but VB.NET complains about DataTable not having a = operator.

How can I force it to use the assignment operator instead of the equality operator?

In C# this works perfectly fine: () => this.existingImports = this.GetImportedAds()

For now the solution will be to use a standalone method, but that's way more code than needed.

View 1 Replies

VB - Cascading IEquatable(Of TEntity) - Check Equality Between EntityId

Mar 14, 2010

I have several entities I need to make IEquatable(Of TEntity) respectively. I want them first to check equality between EntityId, then if both are zero, should check regarding to other properties, for example same contact names, same phone number etc. How is this done?

View 1 Replies

Finding Items In One List That Aren't In A Second List Using Linq

Jan 25, 2011

I have two generic lists, named ListA and ListB. Both ListA and ListB could potentially have duplicate items. What I would like to do is use LINQ to grab the items in ListB that are not in ListA, but I'm unsure how to do so.

View 8 Replies

Re-write Conditional Logic That Involves Checking Three Nullable(Of T) Values In An Equality Operator Overload?

Jan 28, 2011

So I'm writing the equality operator overload (Operator =())for a custom object, and the resulting mess of If conditionals is just an eyesore. But so far, it seems like the only sane way to check the values to as to match the specific behavior of this object.

The rules are:Num1 is required, period, and both the left and right operands and must be equal for True. Else, False.Num2 is optional, but if specified, must be present for both the left and right operands, and must be equal for True. Else, False.Num3 is optional, but can only be specified if Num2 is also present. Else, False.Num3, if specified, must be present for both the left and right operands, and must be equal for True. Else, False.

[Code]..

I also know that I could cache elements of the checks into booleans and then use those to reduce the amount of text. But that seems like a waste of cycles just for code readability. So I wanted to know if the SO community had better thoughts on reorganizing it, just in case I'm being too verbose with my checks.

View 1 Replies

C# :: Determining Object Equivalence For Value Types, Reference Types And ILists?

Nov 1, 2009

I have a class with a Property called 'Value' which is of type Object.Value can be of any type, a structure, a class, an array, IList etc.My problem is with the setter and determining whether the value has changed or not.This is simple enough for value types, but reference types and lists present a problem.For a class, would you assume that the Equals method has been implemented correctly, or just assume that the value has changed every time the setter is called?If I did assume it's changed, then perhaps I should assume it for value types as well, so that the behaviour is consistent.

View 2 Replies

Compare Two Types In Dictionary Of Types .net?

Jun 23, 2012

I need to compare two dictionary values if the types stored are equal, this is what i have

if gettype(Args(key)) = gettype(argtypes(key)) then
'' do something
end if

[Code]....

View 1 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

.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







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