Hashset For Contains With List(of String) .net?

Sep 20, 2010

Would the following:

Dim stringlist As List(Of String)
Dim stringlisthas = stringlist.Contains("thing1")
be any slower than
Dim stringlist As List(Of String)
Dim stringlisthash As New HashSet(Of String)(stringlist)
Dim stringlisthas = stringlisthash.Contains("thing1")

Is a hashset needed for contains?

View 1 Replies


ADVERTISEMENT

Differences Between A HashSet(of T) And A List(of T)

Oct 10, 2011

What are the differences between a HashSet(of T) and a list(of T). I recently discovered HashSet and it seems to be substantially faster and uses much less memory than a list, so why use a list at all ?

View 5 Replies

.net - Function To Accept List(Of String), Array & String And Similarly Return List(Of String)?

Jul 29, 2011

I want the Function to accept List(Of String), Array & String and similarly return List(Of String), Array & String respectively. The Function simply adds a string (month) to the input collection. I just want to use it for string, array and list with needing to think of conversions.

[Code]...

View 2 Replies

.net - Using .Contains Method With Cached Hashset

Jul 26, 2011

I know that the .Contains method on a hashset is fast. My question is what is the best method for getting the hashset data before repetitively using the .Contains method?

I can think of 2 options. Both of these examples would be called in a loop of undetermined length.

1) Call the method that returns the cached hashset directly and use the .Contains method.

IF (GetHashSetMethod.Contains("TESTVALUE") THEN BLAH, BLAH, BLAH...

2) Create a new hashset outside of the loop and load the cached hashset data into it so the method that returns the hashset is only called once, then use the .Contains method.

DIM HashTest AS HASHSET(OF String) = GetHashSetMethod

Then in loop:

if (HashTest.Contains("TESTVALUE") THEN BLAH, BLAH, BLAH...

I have been using method 1. Should I even think about switching to method 2? Is there a 3rd option I haven't even thought of? Does it even matter because the data is cached to begin with?

View 2 Replies

Using A Custom Class In HashSet

May 30, 2010

I created a custom class which just stores 3 byte values, (R G B to be exact), which constantly change. So my idea was to store that class in a HashSet, then create a new instance of the class (with different byte values) then add that to the HashSet. There can be duplicates, which is why I decided to use a HashSet, which will ignore an item if it's allready been added. Doing this on a List would be too slow.But I've ran into a problem. Adding a custom class to hashset seems to only allow 1 to be added. I assume this is because its hashing the class object while ignoring the data (byte rgb values) it contains? Is there a way around this? It's possible to convert the RGB to Color and just use that in the HashSet, but conversion is a bit too slow.

View 2 Replies

Display A HashSet As Either A Collection Or An Array In The PropertyGrid?

Dec 21, 2011

How do I Display A HashSet As Either A Collection or an Array in the PropertyGrid.I wish there was some Attribute that allow me to display IEnumerable as an Array...but so far my attempts to do that have failed!My current solution is unacceptable in the new places I want to use it in

[Code]...

View 3 Replies

Generate Random Images Without Repeat Using Hashset?

Jan 10, 2010

I am trying to generate random images from access database using hashset as it is said to be unique and there won't be any repeated images appearing. But, it doesn't seem to work. ow can i get it to work? By the way, i am very new to the concept of hashset.

Private Function GetImageFromByteArray(ByVal picData As Byte()) As Image
If picData Is Nothing Then
Return Nothing

[code].....

View 1 Replies

C# - With LINQ, How To Transfer A List<List<string>> To List<string>

Dec 15, 2010

I got an object of List<List<string>>I need to bring this into a ist<string>I have no idea how to do this with LINQ.

View 1 Replies

How To Generate Random Images From Access Database Using Hashset?

Jun 22, 2010

I am trying to generate random images from access database using hashset as it is said to be unique and there won't be any repeated images appearing. But, it doesn't seem to work.

How can i get it to work? By the way, i am very new to the concept of hashset.
Private Function GetImageFromByteArray(ByVal picData As Byte()) As Image
If picData Is Nothing Then
Return Nothing
End If

' is this is an embedded object?
Dim bmData As Integer = If((picData(0) = 21 AndAlso picData(1) = 28), 78, 0)

' load the picture
Dim img As Image = Nothing
Try
Dim ms As New MemoryStream(picData, bmData, picData.Length - bmData)
img = Image.FromStream(ms)
Catch
End Try

' return what we got
Return img

End Function

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Panel1.Visible = False
Panel2.Hide()


Dim conn As New OleDbConnection
Dim DA As OleDbDataAdapter
Dim DS As New DataSet


conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db1.mdb;User Id=admin;Password=;"

DA = New OleDbDataAdapter("Select Empty, EmptyName, Target, TargetName from PicturesDisplayed", conn)
DA.Fill(DS)

Me.PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage


Dim oledbconnection As OleDbConnection
oledbconnection = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:Documents and SettingsAdministratorDesktopdb1.mdb;Jet OLEDB:System Database=system.mdw;")

oledbconnection.Open()
Dim command As OleDbCommand
command = New OleDbCommand("select count (*) from PicturesDisplayed", oledbconnection)
Dim count As Integer
count = command.ExecuteScalar()
oledbconnection.Close()


Dim randomImage As New HashSet(Of Integer)
' Create a integer and new Random object
Dim intPic As Integer
Dim rand As New Random

'Pick a random number between 0 and the number of images in database
intPic = rand.Next(0, count)
randomImage.Add(intPic)

PictureBox1.Height = 256
PictureBox1.Width = 256

PictureBox2.Height = 256
PictureBox2.Width = 256


Dim pic1x As Integer = _
(Me.ClientSize.Width - PictureBox1.Width) 2
Dim pic1y As Integer = _
(Me.ClientSize.Height - PictureBox1.Height) 2
PictureBox1.Location = New Point(pic1x, pic1y)


Dim pic2x As Integer = _
(Me.ClientSize.Width - PictureBox2.Width) 2
Dim pic2y As Integer = _
(Me.ClientSize.Height - PictureBox2.Height) 2
PictureBox2.Location = New Point(pic2x, pic2y)

' Now set the picturebox image equal to the image chosen from the array randomly using the random
PictureBox1.Image = GetImageFromByteArray(DS.Tables(0).Rows.Item(intPic).Item(0))
PictureBox1.Visible = True
PictureBox2.Image = GetImageFromByteArray(DS.Tables(0).Rows.Item(intPic).Item(2))
PictureBox2.Visible = False


If (randomImage.Count = count) Then
Me.Close()
End If

End Sub

View 1 Replies

Play With List Of List Of String With Javascript Or Jquery Using Ajax?

Dec 5, 2011

We're working on a big ASP.NETVB.NET website project. I need to populate three dropdownlists. To last two are independent of the previous ones. The population data comes from an SQL Server. I'd have no problem doing this with code-behind with post back but we don't want any PostBacks so I started to develop this in AjaxjQuery.

[Code]...

View 1 Replies

Cast/convert From List(Of DataRow) To List(Of String)?

May 22, 2012

I'm trying to solve a problem regarding types of list. First of all I have a stored procedure in my DB which does a select of a single column and I try to proceed it in my app in VB. By making a method function I declared a DataTable that loads through the SqlCommand(with the CloseConnection behavior). After that I publicly declared a List(Of String) which needs to be populated with the rows/items from the stored procedure that is on the way. Below is my snippet of the code:

Dim dt As New DataTable()
Try
If conn.State = ConnectionState.Open Then

[Code]....

It's LPrefix = collection.Cast(Of String)() where I get an exception error telling me that I can't really convert it. The old fashion way is to iterate with for/for each loop but that's not what I want for best use of performance especially if the list will have thousands of rows from a single column. So basically, I want to insert those items from that DataTable to the List(Of String) without For/For Each loop.

Running on VisualStudio2010 Ultimate, .NET FrameWork 4.0.

View 2 Replies

Vb.net - Convert From Custom List To List Of String

Mar 25, 2010

I have the following code:

[code]...

The intention is to convert an IList of custom objects to a string equivalent comprising each element in the Ilist. Unfortunately I can't seem to find a way to get the underlying data of the custom object, and of course as in the above example, using object simply gives me a string of types definitions, rather than access to the underlying data.

View 2 Replies

Compare List(Of String) To Another List(Of String)

Dec 30, 2009

I have two List(Of String) both containing several hundred thousand results.

Private Function AddUniqueFiles(lNewFiles as List(Of String)) As outList(Of String)
Dim aCounter As Integer = 0
Dim files As New inList(Of String)

[Code]....

However the time it takes to do this comparison can be very long indeed - is there a better way of doing this type of comparison... All I am trying to do is add values from List2 in to List1 which are not already present in List1 - So in effect adding new Unique values found in List 2 in to List 1. I am only looking for performance improvements - nothing else.

View 7 Replies

Sorting - Sort List(of String()) Using A Variable Index Into String() As Key ?

May 30, 2012

I have a List(of String()). I have written a custom comparer (implements IComparer(of string)) to do an alphanumeric sort.Is there a way to sort the List using a given index to determine which position in the String() to sort by? In other words one time I might sort by Index = 0 and another time by Index = 3. The length of all String() in the list is the same.For reference this question is similar to Sort List<String[]> except I am using VB.net and that question is hardwired to Index=0.

EDIT from OP's comments:I started simple with the non custom comparer but I am getting an error: expression does not produce a value. Not sure what I am doing wrong.Here is the code:

Public Shared Function SortListOfStringArray(ByVal ListOfStringArray As List(Of String()), ByVal SortByIndex As Integer) As List(Of String())
Return ListOfStringArray.Sort(Function(x, y) x(SortByIndex).CompareTo(y(SortByIndex)))
End Function

View 1 Replies

Convert List Of String To A String Separated By A Delimiter

Apr 15, 2009

Whats the best way to convert a list(of string) to a string with the values seperated by ,

View 3 Replies

Reorder A List Of String Into A New List?

Mar 29, 2012

I want to reorder a list of strings into a different list of strings. I am creating multiple loops to do this, however i was wondering if there was a better way to do this.

Dim values As New List(Of String)
For Each val As String In vals
If val.Contains("10") And val.Contains("Year 1") Then

[Code]....

There are going to be quite a lot of these loops to do what I want can anyone offer any help or a better way to go about doing this? Note that I want the values list to return 10,10,10,20,20,20 so that lines that have 10 should be added first and lines with 20 then afterwards.

View 2 Replies

Convert A List(of String) To String()?

Nov 11, 2011

Dim namelist As List(Of String) = New List(Of String)
namelist.Add("Hi")
namelist.Add("Hello")

[code].....

View 4 Replies

How To Declare List(Of String()) With String(2)

May 5, 2012

I am trying to declare List(Of String(2)) and it doesn't work

I understood that if I specify the length of the string() the compiler will not need to guess the length and it will be more fast that way, is it correct?

View 3 Replies

List(of String) To Dim Item()() As String

Oct 22, 2011

I have a list with a few items ( changes once in a while ) named itemlist

[Code]...

View 9 Replies

.net - Convert A List (Of KeyValuePair(Of String,Int32) Into A Dictionary(Of String, Int32) Using .ToDictionary?

Nov 2, 2010

To be able to sort a dictionary by value I'm using this code:

Dim idCurrentJobs As IDictionary(Of String, Int32) = New Dictionary(Of String, Int32)
'The string in the dictionary represents a jobname and the integer is a counter for how many jobs im currently are running in the application'
idCurrentJobs.Add("JobName1", 2)

[code]....

View 2 Replies

VS 2008 Parse Text For Fields - Get A String List Of All Values Within [] In A String Of Text?

Oct 18, 2010

What would be the fasted method of get a string list of all values within [] in a string of text? For example: [client_name], are you are doing today? My name is [my_name]. The list of strings would be:

[Code]...

View 6 Replies

Add To A List(Of String) While Using One?

Jan 14, 2010

I'm thinking about making a queue system for my program which uses Asynchronous file downloading.

Now what I'd like to know is if I setup a For Loop like so[code]...

And I add to that list while the program is looping through this, will the program pick up that new Item, or do I need to find a way to abort and restart?

View 3 Replies

Getting A String From A List Box On One Form To A List Box On Another Form In VB 2008

Oct 17, 2010

I need to get a string from an items collection in a list box on one form to a list box on another form in VB 2008. Here is the code (I've tried a couple ways in the code to get the values over).

Public Class frmPrintBooks
Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles btnClose.Click

[Code]....

View 3 Replies

Add Text To A List(Of String)?

May 31, 2009

I was wondering how to add the text from a text file to a List(Of String), one line per item (in the list).

View 19 Replies

Get List Of String From Objects?

Aug 26, 2011

I was wondering how I could go about getting a list of string from a list of objects, while removing duplicates[code]....

View 2 Replies

Have A List Containing One String And Two Numbers?

Jan 28, 2011

Can I have a List containing one string and two numbers? Or I can only have one type of element?

View 3 Replies

How To Convert Csv String To List

Apr 8, 2011

[Code]...

How can I convert a csv string into a list in vb.net?

View 3 Replies

How To Use For Each Loop On A List Of String

May 13, 2010

Public Class CustomerList : Inherits System.Collections.CollectionBase

Public Sub Add(ByVal name As String)
Me.InnerList.Add(name)
End Sub
Public ReadOnly Property items(ByVal i As Integer) As String
Get
Return CType(InnerList.Item(i), String)

[Code]...

View 1 Replies

Initialize List Of String?

Jul 6, 2010

Dim pix() As new List(Of String) = {"*.jpg", "*.avi", "*.mov"}
Dim pix As new List(Of String)() = {"*.jpg", "*.avi", "*.mov"}
Dim pix() As List(Of String) = {"*.jpg", "*.avi", "*.mov"}
Dim pix As List(Of String)() = {"*.jpg", "*.avi", "*.mov"}

Does it matter where the () are?

What difference does New make?

View 1 Replies

Way To Order A List Of String

Jun 25, 2012

I have a list(of list(of string)) in vb.net which is a list that contains lists that have 5 string list items in them.

I want to sort the lists by the second item in the contained lists but I don't know what parameter is needed in the .sort method. What do I need to put in as a parameter. I read something about writing a comparer function and putting that in the brackets but I don't understand how that works.

View 3 Replies







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