Anonymous Methods In .NET - Foreach?
May 16, 2011
I try to replace the classic For Each with the LINQ ForEach method in VB.NET
Dim singles As New List(Of Single)(someSingleList)
Dim integers As New List(Of Integer)
For Each singleValue In singles
[code]....
How should I correctly do it (using anonymous methods = without declare a new function)?
View 2 Replies
ADVERTISEMENT
Sep 16, 2011
How do I use RemoveHandler with anonymous methods? This is how I add a handler for MyEvent event of the class MyClass
AddHandler MyClass.MyEvent, Sub()
...
End Sub
How do I then use RemoveHandler to remove the handler for the MyEvent event
View 1 Replies
Jul 1, 2010
I am trying to get my code working as per the instruction on [URL]So far I have the wrapper:
Public Delegate Function PredicateWrapperDelegate(Of T, A)(ByVal item As T, ByVal argument As A) As Boolean
Public Class PredicateWrapper(Of T, A)
Private _argument As A
Private _wrapperDelegate As PredicateWrapperDelegate(Of T, A)
[code]....
Then I try to call it from my code:
Dim children As List(Of String) = toplevel.FindAll(New PredicateWrapper(Of Integer, Integer)(Did, AddressOf DidMatch))
I then get an error on DidMatch ... Error Method 'Public Function DidMatch(item As DeptMenuData, did As Integer) As Boolean' does not have a signature compatible with delegate 'Delegate Function PredicateWrapperDelegate(Of Integer, Integer)(item As Integer, argument As Integer) As Boolean'.
View 1 Replies
Jul 9, 2009
I'm a Linq noobie, maybe someone can point me in the right direction. What's wrong here? These anonymous types seem to have the same signatures.
[Code]...
View 2 Replies
Aug 29, 2011
This is the original code in c#
public class CategoryRepository: RepositoryBase<Category>, ICategoryRepository
{
public CategoryRepository(IDatabaseFactory databaseFactory)
: base(databaseFactory)
[Code]...
Does anyone has an idea what i should change to let it work and let my UserRepository use the methods in RepositoryBase while implementing the IUserRepository?
View 1 Replies
Jun 24, 2011
I am working with a vb program, but there is something strange on one of my .vb code pagewhen i put the "dot" afther the object name its dont show the methods availables for this objectbut on other vb code pages i can see it. but in this one no.for exmaplethis is a piece of code: Dim sb As New StringBuilder()
View 3 Replies
Mar 29, 2010
I am not sure how clear my question is by the title, but I am trying to make Class methods instead of Instance methods in Visual Basic that way I don't have to waste memory and code creating temporary objects to execute methods that don't need instance variables.
I am not sure if you can do that in VB but I know you can in Objective-C by using either a "+" or "-" sign in front of the method declaration. And in C++ (at least I think, I can't remember) you put the static keyword or const keyword in front of the function.How would I do this in VB if it is possible? Or should I just make a separate set of functions that are not members of a class?
View 2 Replies
Mar 12, 2009
My co-worker said that in a previous interview, he learned that foreach is faster in VB.Net than c#'s foreach. He was told that this was because both have different CLR implementation.
Coming from a C++ perspective, I'm curious on why this is and I was told that I need to read up on CLR first. Googling foreach and CLR doesn't help me understand.
Does anyone have a good explanation on why foreach is faster in VB.Net than in c#? Or was my co-worker misinformed?
View 5 Replies
Apr 15, 2010
tell how to form this to the correct Syntax?ere the sample in sequential form:ForEach ctrl AsCheckBoxIn tblCKBoxCollection.Controlsctrl.Checked =
View 1 Replies
May 21, 2009
I have searched high and low for documentation on how to use this feature. While the loop I could write would be simple and take no time, I really would like to learn how to use this. Basically I have a class, say, Widget, with a Save() sub that returns nothing. So:
Dim w as New Widget()
w.Save()
basically saves the widget. Now let's say I have a generic collection List(Of Widget) name widgetList(Of Widget) and I want to run a Save() on each item in that list. It says I can do a
widgetList.ForEach([enter Action(Of T) here])
....but how in the F does this work??? There is no documentation anywhere on the intrablags.
View 5 Replies
Oct 14, 2011
I'm writing a loop to go through the first array of a 2D loop, and I currently have it like this:
For Each Dir_path In MasterIndex(, 0)
'do some stuff here
Next
But it's giving me an error, saying it expects an expression in the first field. But that's what I'm trying to do, loop through the first field. How do I fix this? What would I put in there?
EDIT: to clarify, I'm specifically looking for the 0th element in the subarray of each array, that's why that second field is constantly 0.
View 2 Replies
Mar 1, 2010
I have a list like this
[Code]...
How can I iterate the list with ForEach to get one string with the emails like this [URL]
View 5 Replies
Aug 24, 2010
is it possible to use foreach with a 2d array?
View 8 Replies
Aug 30, 2009
What i'm doing is getting values from some html, i use a regex to retrieve all the fields, but there are some fields brought back i don't need (4 out of 11) i know the names of these fields, but was wondering if there was a way i could filter out the ones i don't need in the foreach:[code]
View 5 Replies
Aug 3, 2010
I recently changed a For Each loop to a Parallel.ForEach loop. I'm concerned about an object being declared outside the loop but assigned while iterating in the loop. Here is the simplified code.
Dim results As ModelResults
Dim noResultsModel As New List(Of ModelResults)
Dim lock As New Object
Parallel.ForEach(_modelEngines,
Sub(model)
[Code]...
Is there a potential race condition with the results object? Would anything be different if I moved the declaration of results into the for loop?
View 1 Replies
Apr 15, 2012
I'm flummoxed I'm using VB.Net, Linq, and a DataContext. My DataContext contains a table 'transactions'.
I first declare an IQueryable(Of transaction) and assign it to nothing. I build a predicate in a foreach loop and use a transactions.Where(predicate) to assign the IQueryable a value. If I do an IQueryable.ToList(), I get a number of items in the collection.
However, on the next iteration of the loop, the IQueryable.ToList() gives me 0 items.This is driving me crazy. I tried to use the LINQ to SQL Debug Visualizer with VS2010, (I recompiled the 2008 version with the new reference) but no dice - I can't see the SQl generated or what's inside the IQueryable.
[Code]...
View 2 Replies
Jun 13, 2012
I am making a program that automates the seperation of a csv file. We read the csv in through and then assign the "line" using a split command to an array. After that we go through each "cell" in the array and put an = in front because this causes leading zeros not to be lost. Here's the code.
arLine = line.Split(replace)
For Each cell As String In arLine
cell = cell.Replace(",", "")
cell = String.Format(cellFormat, cell)
Next
arLine is the array and replace is the delimiter, in this case a pipe not that it matters.'
When it goes through, the arLine is correct but the values in each cell are not changing, any thoughts? newer to VB.net and need direction
View 2 Replies
May 12, 2009
In C# i just put the method in the parentheses that i want to run on each row of the collection, but it isn't working in VB.NET.[code]...
View 1 Replies
Apr 18, 2012
I am having an issue extracting the value from every row in column "MobileID" within a table named "dt" that is within a dataset named "ds".Here is how the dataset and datatable are created.[code]
View 1 Replies
May 8, 2009
I have the following for each loop which loops through a registry key and reads all the values:
Dim returnValue As RegistryKey = Registry.LocalMachine.OpenSubKey("SOFTWAREMicrosoftWindowsCurrentVersionRun")
Dim keyname As String = "HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionRun"
Dim values() As String = returnValue.GetValueNames
[code].....
What I am trying to have been highlighted in bold.. Each time the loop executes and reads a value from the registry, I want the code to create a checkbox which has a unique name and text according to the value that was read... So the number of checkboxes will depend on number of values that is got from the registry...But this doesn't work. It only creates one text box and the text of the textbox is also incomplete...
View 7 Replies
Jul 9, 2009
I have the following Method:
CODE:
Everything is working fine except for one part. The part where the second foreach loop runs. If I only have one plugin installed it puts 2 entries in the list. The reason is because it has 2 rows and it is adding it twice. I know what the issue is I just am drawing a blank right now.
View 11 Replies
Apr 16, 2010
I've been trying to follow the examples I've found online and, well, I can't really get my head around what I've done wrong.So, I have a simple piece of code to search for a machine in AD, as so. [code]
View 5 Replies
Oct 18, 2010
I can't seem to get the syntax right for a simple Parallel.Foreach Loop.
This is how I would normally iterate a SearchResultCollection
Dim src As SearchResultCollection = DSearch.FindAll
For Each x As SearchResult In src
Debug.WriteLine(GetProperty(x, "Name"))
'Parallel.ForEach(x, Function(x) Debug.WriteLine(x))
Next
As I have (obviously) misunderstood it this should be the syntax for the Parallel.Foreach
Parallel.ForEach(src, (Sub(x As SearchResult) GetProperty(x, "Name")))
Parallel.ForEach(src, Function(x) Debug.WriteLine(x))
It's not that though. What's the correct syntax here?
View 13 Replies
Mar 9, 2009
i'm using a foreach to loop through my regular expression like:
For Each secwordMatch As Match In secwordmatches
Dim secWord As String = secwordMatch.ToString
Next
[code].....
View 4 Replies
Apr 8, 2009
I have a form called frmMapViewer. In this form I 25 labels showing districts of my country. think I want to assign names(text property) to each label.[code]...
View 5 Replies
Aug 18, 2011
Why there is only a static/shared version of ForEach for arrays?
IE: ForEach<T>(T array[], System.Action(Of T) action[])
I assume this has something to do with the type inference requirements of implementing an instance method, but when you declare your array you provide type right?
View 2 Replies
Jul 29, 2011
How to write xml foreach datarow in dataset? I have dataset with 5 record in table, i want write to xml file with 5 xml file. in one xml file have one record.
View 2 Replies
Nov 5, 2011
I am trying change from Delegates to Parallel.ForEach I see the below works fine. Imports System.Threading.Tasks
Sub Main()
Dim secs() As Integer = {2, 3, 1}
Parallel.ForEach(secs, AddressOf Method2)
End Sub
[Code]...
View 2 Replies
Dec 17, 2010
Is there a way to start same Thread form foreach loop
Sub
For Each lvItem As ListViewItem In _ListView.SelectedItems
tThread = New Thread(AddressOf Me.myFunction())
[Code]....
In my case, when i select one item from list it is working fine...but when i select more than one files it odes not work.
View 3 Replies
Apr 2, 2011
I have a List(Of SomeObject) that I enumerate over using a For Each loop. This SomeObject contains a Property that references another Object, as such
Class SomeObject
Public Property Another As AnotherObject
Get
[Code]....
If not, what is a valid way to do it? (ordinary for loop perhaps?)
View 1 Replies