Implementing IComparer For Custom Objects After Converting A Dictionary To SortedDictionary?

Jun 5, 2012

I'm having trouble implementing an IComparer method. Essentially, I want to compare the properties of two custom objects (the properties are of type integer).dE is a Dictionary(Of String, customObj)prTabIndex is a property of customObj and is of type Integer (these hold true for all examples)After some more searching I found this thread which suggested 3 things: a List approach, utilizing LINQ, and using some C# 3.0 features. I've tried three different ways:...rolling my own IComparer implementation:

Public m As Sub(ByRef d As Dictionary(of String, customObj))
Dim sortedD As New SortedDictionary(Of String, customObj)(d, myCompare)
End Sub

[code]....

Note that VS2008 has underlined 'dE.ToDictionary...' (to the end of the line) and giving me two messages depending on where I hover my mouse:

1) "Data type(s) of the type parameter(s) in extension method 'signature' As 'signature defined in 'System.Linq.Enumerable cannot be inferred from these arguments. Specifying the data types explicitly might correct this error. Seen while hovering over "ToDictionary".

2) Nested function does not have the same signature as delegate 'signature'. Seen while hovering over anything after "ToDictionary".

Q1) How far off am I in each of the implementations?

Q2) Which one is the computationally least expensive? Why?

Q3) Which one is the computationally most expensive? Why?

View 1 Replies


ADVERTISEMENT

Implementing Generic IComparer Of Own Class?

Jun 17, 2012

I am trying to create a class implementing the generic IComparer of my own class "Stellungen" (which translates to positions, like on a chess or checkers board).

This is what I got:
Private Class comparer(Of Stellung)
Implements System.Collections.Generic.IComparer(Of Stellung)
Public Function Compare(x As Stellung, y As Stellung) As Integer Implements System.Collections.Generic.IComparer(Of Stellung).Compare
End Function
End Class

Problem is: inside the function I have no access to any fields of my class. If I start off with x. Intellisense will only give me .Equals, .GetHashCode - the methods you get on a type but not on an instance. Visual Studio 10 also highlights this, in the definition of the function the bits "x as Stellung" and "y as Stellung" are written in light blue, meaning it is a type and not an actual object. How do I access the things I want to compare inside my class?

View 1 Replies

Sort Listview Using A Custom Icomparer ?

Jan 9, 2009

I'm trying to sort my listview using a custom icomparer. I have to sort numbers, strings, dates, and currency.

Here's the code to sort:

compareResult = ObjectCompare.Compare(listviewX.SubItems(ColumnToSort).Text, listviewY.SubItems(ColumnToSort).Text)

The problem is it sorts numbers wrong, such as:
10
2
3

instead of
2
3
10

View 3 Replies

Multithreading - Create Custom Objects/list Of Custom Objects In .NET?

Jan 24, 2010

I need two seperate lists, which every item is Integer, String, Bitmap - and one which every item is Integer, String String. However I don't know how to do this, or even where to look - I've googled for custom objects and custom object lists. What I'm trying to do is this.Custom Object1 is Integer, String, Bitmap Custom Object2 is Integer, String, String

In one thread I'll be adding items to List1(Of Object1), and processing them, and adding the results to List2(Of Object2), however I need to be able from other threads to look at the list and say only give me the items where Integer = (my thread ID), is this possible? Any help, or even links to information that would be relevant to this request would be helpful?

View 2 Replies

.net - Filter Custom Dictionary With LINQ ToDictionary - "Unable To Cast Object Of Type 'System.Collections.Generic.Dictionary`2"

Jul 7, 2010

I have created a Dictionary class (MyDictionary for the example). I am currently trying to pass MyDictionary into a function, filter it into a new instance of MyDictionary and pass this new instance into another method. When I am attempting to create the second instance from the filtered first instance of MyDictionary via Lambda Expressions and the ToDictionary Method, I am getting the following error:

Unable to cast object of type 'System.Collections.Generic.Dictionary`2[System.Int32,System.String]' to type 'MyDictionary'. I have simplified the example and recreated it in LINQPad and am getting the same error.

Here's the simplified version of my code:

[Code]...

View 2 Replies

Implementing Custom Login For MVC?

Oct 29, 2009

I'm new to ASP.NET MVC and need abit of advice on how to implement the following.The site is a heavily used site with roughly 200 users internally (intranet). We use forms authentication hitting a SQL Server DB (not windows integrated).

Some actions are protected, some are viewable by anyone and some are viewable by both - so if theres a logged in user they see their stuff from the DB, otherwise they see a temporary profile - much like StackOverflow.

How would I go about implementing a security model for this scenario? Can I reuse the existing framework in ASP.NET MVC and use the authorization filters?

View 3 Replies

Implementing Custom Configuration Section Handler?

Nov 2, 2010

I have put together a custom configuration section handler (vb.net), based on gleanings from a variety of sources (including stackOverlflow), however when I come to use it, I get the following error message "The Configuration property 'deviceconfig' may not be derived from ConfigurationSection." The app.config file looks like this:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>

[code]....

View 1 Replies

Update Values Of Objects In A Dictionary?

May 12, 2011

I add objects (structure type) to a dictionary with string keys.

i don't figure out how to update a value of a object.

i use TryGetValue to get a reference to a object of the dictionary collection.

But the changes i made at the referenced object are not made at the object at the dictionary.

Any hints how to get a object reference to change values without to re-add the complete object?[code]...

View 5 Replies

ASP.NET Cast ArrayList Of Objects To Custom Objects?

Aug 9, 2011

getting the following error Unable to cast object of type 'System.Object[]' to type 'OrderService.webdirect_WebLinesRow[]'. On the line

webdirect(web_companyID, web_locationCode, web_customerNumber, web_orderNumber, web_orderReference, web_orderDate, webLinesArray.ToArray(), o_Company, o_LocationCode, o_CustomerNumber, o_OrderNumber, o_OrderStatus, o_OrdDescrip, webRespArray)

I created the webLinesArray.ToArray() array as such

Dim webLinesArray As New ArrayList()

Am I missing an additional cast or something ?

View 1 Replies

Populating Dictionary - Creating Objects Within Loop?

May 16, 2010

I am trying to populate a dictionary with objects created from data in a recordset, but am having difficulty with VB's object referencing. I am very new to VB. Pseudo code of what I am trying to do:

dim dict as Dictionary
rs = getRecordSet
while rs.moveNext
set myObj = new MyClass
myObj.properties = rs.relevantFields
dict.add myObj.getUniqueKey, myObj
wend

However, all 'objects' in the dictionary are actually references to the most recently created (and thus last) object in the dictionary. I know why what I am doing above is not working, but I don't know the correct way to do it so that each element in the dictionary is it's own object.

View 2 Replies

Store Objects With Key In Some Sort Of Collection/Dictionary?

Jun 10, 2012

I need to Store Objects with Key like:

Key: <Fontname & FontSize> / Object: <Font Object>

Example content:

ArialRegular8 | <Corresponding Font Object>
ImpactItalic10 | <Corresponding Font Object>
TimesRomanRegular12 | <Corresponding Font Object>

These font types come from an external library, the real type is DocumentFont, I prefer not to store just values and recreate the font object later, so I need to store the object, and i want to be able to call Contains() later without looping. like for example Dictionary (of T Key, T Value), is this the best option? Also, to be able to call Contains(), i will have to overload function Contains() using an Interface or this is already built-in in some Collections / Dictionaries when using a String as Key?

View 3 Replies

Implementing A Custom Control With A Typed Collection For Use At Design Time

Oct 14, 2010

I am having a problem with the Visual Basic property collection editor .

I have created a Custom Type

Public Class Field
Private Item As Integer
Private Name As String = "FieldName"

[ode]....

View 1 Replies

Linq To Objects - (C#) Creating A Dictionary From An Existing List Without Looping?

Aug 31, 2011

I don't know if this is doable, maybe with Linq, but I have a List(Of MyType):

Public Class MyType
Property key As Char
Property description As String
End Class

And I want to create a Dictionary(Of Char, MyType) using the key field as the dictionary keys and the values in the List as the dictionary values, with something like:

New Dictionary(Of Char, MyType)(??)

Even if this is doable, internally it will loop through all the List items, I guess?

View 3 Replies

.net - Custom Dictionary Object?

Dec 1, 2009

I want to extend the VB.NET dictionary object to not bitch about an item being already in the associative array.This is what i want to do:

[Code]...

My problem now is:How can I replace the (of object, object)line to let the dictionary be of generic/customizable type?

View 1 Replies

Make Dictionary And Custom Class?

Aug 6, 2010

I need use a collection of differents types, this is:id (long), name (string), type (integer), open (byte) idReg (integer)I would like use it like an array but using the "field" id as key. The only way that i found for do it possible is using a custom class and then a dictionary.This is the custom class:

Public Class frmColeccion
Private m_name As String
Private m_type As Integer

[code]....

View 8 Replies

How To Auto-insert A Code Snippet When Implementing Interface Like When Implementing IDisposable

Aug 10, 2010

Is it possible to automatically insert a Code Snippet when an interface is implemented? If so, how do you do it? I am looking for something similar to when you implement IDispoable in VB.[code]This will be used by web forms when transfering parameters from one page to the next using Server.Transfer

View 1 Replies

Converting Objects To Datetime?

Nov 3, 2011

I am having a problem converting objects that are dates into actual dates. I'm reading in values from a datatable, and sending them to a JavaScriptSerializer so I can use the values in an open source calendar called fullCalendar.The problem is, the feed from the JavaScriptSerializer contains dates and a boolean value.

My code looks like this:
Dim rows As New List(Of Dictionary(Of String, Object))
Dim row As Dictionary(Of String, Object)

[code].....

View 1 Replies

Forms :: Converting Strings To Objects?

May 6, 2010

Can you look at this code? It's a class module that I made so I can make our application more modular.

In the code there are 3 lines of code which have this as part of it: FormBrowseAttendance.ComboBoxLookupStudent.how I can change the coding to refer to this portion of code using these parameters:

pComboBoxName
pNameOfForm

I'm assuming these need to converted is some way but I don't know how to do it.

[Code]...

View 3 Replies

How To Add Custom Objects In To Listbox Of VB 2010

Aug 18, 2011

I am developing one vb application. In that I have one list box. I want to add different types of Items. Like Different Colored and differently aligned text(Like one item item is right aligned and one more is left aligned). Can you please tell me how can i do the same.

View 2 Replies

Updating Custom Objects With ObjectDataSource?

Mar 7, 2011

I am using VS 2010 web application projects

I have an object datasource connetced to a custom object. The data from objectdatasource is displayed

in the Formview. When i try to do the Update. It sends me two empty objects of the class.

This is my objectdatasource

<asp:ObjectDataSource ID="obj1" runat="server" SelectMethod="GetValues"
TypeName="CustomDAL" ConflictDetection="CompareAllValues"
UpdateMethod="Edit" OldValuesParameterFormatString="old_{0}"

[Code].....

View 1 Replies

VS 2010 Custom Objects And Properties

Nov 13, 2011

I'm working on a project where I need to information on all the monitors connected to a computer and then write a configuration file based on that. I can already get the screen information by creating a new instance of screen and reading the information such as index, bounds and everything else.I'm trying to create a virtual screen object to hold the information from the screen so I can work with it, or add other properties to it.[code]This all works perfectly how I want it to. Except I would like to do one more thing. How can I make it so that instead of getting Virtual_Screen.Top, I could get Virtual_Screen.Bounds.Top? That way I could create other properties such as Virtual_Screen.Border.Top..I have no idea how to code, or what that would be called. It's hard to search for something you don't know the name of.

View 5 Replies

.net - SortedDictionary - Comparer Only For Sorting

Oct 31, 2010

I have a list of keys and values that I would like sorted by key via a custom Comparer(Of T). I tried using a SortedDictionary, but kept getting incorrect results because it used the comparer to see if the items were the same. For example calling SortedDictionary.ContainsKey() would return false, even though it did contain the key.

When I stepped through the code after calling ContainsKey(), it would go to the comparer.Compare(x, y) function. It would then only compare against a few of the keys in the dicionary, and somehow skip the matching item (which I ensured did exist). I take it that this is some sort of optimization, where some items are skipped depending on what is returned by the comparer.Compare() function? Is it possible to have a dictionary that only uses the comparer for sorting? EDIT: I am using a Type object for the dictionary's key

[Code]....

View 3 Replies

Using SortedDictionary As Combobox Datasource?

Mar 24, 2010

I have a combobox which i am binding to a sortedDictionary list, so it displays in ascending order. My question is, I need to display "--Select--" as the first option. Is there any way to either:

1) add another item besides for the datasource

or

2) add an unsorted item to the top of the sortedDictionary

View 2 Replies

VS 2010 Using A Combobox With A SortedDictionary?

May 21, 2010

I have a SortedDictionary of type (String, UserPrincipal). The key is the user's UserID and the item is the user's UserPrincipal object.I have bound the combobox to the dictionary like this

ManagersComboBox.DataSource = New BindingSource(_userdict, Nothing)
ManagersComboBox.DisplayMember = "Value"

[code].....

View 2 Replies

Converting Types Using Custom Classes?

Sep 16, 2009

I'm studying for the MCTS exam 70-536 and have come across the following question:Given the following Visual Basic code sample, which interface must the custom class MyClass implement?

Dim a As MyClass, b As Boolean
a = 42
' Convert using ToBoolean.
b = Convert.ToBoolean(a)
Console.WriteLine("a = {0}, b = {1}", a.ToString, b.ToString)

Before even looking at the possible answers, I can't get past WHY on earth would we be converting the number 42 to a Boolean value?? I tried this and as I suspected it did NOT compile! Is this a trick question or am I missing something? I realized that in order for the code to work, I would need to implement one of the interfaces shown in the multiple choices. STILL, would there EVER be a purpose for this particular conversion?

View 4 Replies

Accessing Objects From Within A Custom Object List

Mar 3, 2009

OK - for starters - I'm not even sure that the title of this thread accurately describes what I want to do - but I had trouble verbalizing it. So I will give this a try: In my application, I have a custom object, call it myObject. In addition, I have another custom object called myObjectList which is basically a List(Of myObject).

Up until this point, all of the functions that I have been working with in my BLL and DAL have been shared - I haven't needed a specific instance of my object thus far. I currently need to write a function that finds a particular myObject within myObjectList and returns to me myObject. I know that the List(Of T) has a find method, but from what I have read so far - I don't think it is what I want (doesn't it return true or false? -and also, do I need an existing object to pass to it to see if it is in the list?)

[Code]...

View 5 Replies

Sort ArrayList Of Custom Objects By Member?

Sep 3, 2009

How can I sort an ArrayList of custom objects by public member? Example,If I have a list of article objects, and I'd like to sort the list by the rating member after I've filled the ArrayList

Public Class Article
Public bulletin As String
Public rating As Integer[code].....

Now I'd like to sort uniqueArticles by rating and print articles by rating order.How do I do perform that sort?

View 2 Replies

Use SortedDictionary To Store 65,000 Keyvalue Pairs?

May 17, 2012

I'm thinking to use the SortedDictionary to store 65,000 set of keypairs and from time to time during my program execution, I need to retrieve the value from the this dictionary. May i know will there any concern especially in term of speed of execution if i use this method as above? Is there max. capacity that a dictionary can hold?

Previously, i was thinking to use a simple 2D array to do this, but it mights slow things down because in order to retrieve the value, i might need to loop through the whole array till i found the value that i want.

View 1 Replies

Bind A List Of Custom Objects To A Listbox Control?

Jun 25, 2010

vs2010 vb.net WPF project

This is an experiment to learn something.

I have a class called logitem

it has a datetime property, and a message as string property

I have declared myLogEntries as List(of logItem)

I have a ListBox.

Ok now what?

I have searched but i am getting lost in all the examples.

I have set the ItemsSource=myLogEntries

I think i need a datatemplate or maybe to specify binding source.

I am doing all this in the wpf form loaded event.

I guess i need a sample code for binding a list of collection to a listbox.

View 5 Replies

.net - Performance Of Implementation Of IComparer?

Jul 14, 2011

I'm sorting a collection of type "Document" (usually around 100k records). Sorting usually takes around 4-5 seconds, and I'm wondering if there's a way to speed up sorting by modifying my "DocumentComparer" class which implements IComparer(Of Document). Since the Compare() method would be called hundreds of thousands of times, are there any performance improvements that could be made here that I've overlooked?

[Code]...

View 2 Replies







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