Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    vbnet


Advertisements:










.net - "Using The Iteration Variable In A Lambda Expression May Have Unexpected Results"


Edit: Here is a much more simpler example of this issue (i've deleted my original question):

Dim numbers1 As New List(Of Int32)({1, 2, 3})
Dim numbers2 As New List(Of Int32)({3, 4, 5})
For Each n1 In numbers1
' no warning '
Dim contains = numbers2.Contains(n1)
Next

[Code]...

The local variable number1 is redundant and makes the code less readable as @Meta-Knight already has emphasized. Note: All three ways are safe and give the correct result.


View 2 Replies (Posted: )

Sponsored Links:

Related Forum Messages For vbnet category:
Get: "iteration Variable In A Lambda Expression May Have Unexpected Results"
Possible Duplicate:Why is it bad to use a iteration variable in a lambda expression.why do I get: "iteration variable in a lambda expression may have unexpected results"? Suppose I have the following code:

[Code]...

Posted: Mar 1 at 21:03

View 2 Replies!   View Related
C# - Using Iteration Variable In A Lambda Expression?
[URL]..Module Module1

[Code]...

It says the result will always be 5 namely the final value of i. How come?

They don't put the iteration variable in the "closure"?

Posted: Feb 16 at 7:17

View 1 Replies!   View Related
How To Suppress VB's "Iteration Variable Shouldn't Been Used In Lambda Expression"?
I'm working with LINQ in VB.NET and sometimes I get to a query like

For i = 0 To 10
Dim num = (From n In numbers Where n Mod i = 0 Select n).First()
Next

[code].....

Posted: Sep 30 10 at 10:04

View 2 Replies!   View Related
Set An Indexing Variable In Linq/Lambda Expression?
I have a lambda expression that builds a list ofanonymous types. I would like to include a property in the anonymous type that is a counter. So the first entry is 1, second 2, third 3, and so on.I thought I recallenyone know the syntax for defining an indexing variable as part of a Linq query or lambda expression?

Posted: April 16, 2010

View 10 Replies!   View Related
.net - Unexpected IQueryable Value After ForEach Iteration?
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]...

Posted: Apr 15 at 20:09

View 2 Replies!   View Related
Delegate 'System.Threading.ThreadStart' Requires An 'AddressOf' Expression Or Lambda Expression As The Only Argument To Its Constructor?
I got this Error. below is my code.

GenerateTheList is function.Need help
Private Sub buttGenerate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buttGenerate.Click
Dim thread1 As New Thread(New ThreadStart(GenerateTheList))
thread1.Start()
End Sub

Posted: January 23, 2010

View 1 Replies!   View Related
AddressOf' Expression Or Lambda Expression
From this code

[Code]...

If I put New Action(AddressOf PrivateMesage), then I get the following error: Bounds can be specified only for the top-level array when initializing an array of arrays. on the following code

[Code]...

Posted: Feb 22, 2009 01:50 AM

View 2 Replies!   View Related
Linq To Xml - Unexpected Search Results
Just when I was thinking that I had Linq To Xml sussed I'm faced with yet another error! I think if I was to understand the linq search process in general better I might have more success, so any good links regarding that are also welcome. To my problem however; using the code below:

[Code]...

Posted: Mar 10 11 at 19:04

View 1 Replies!   View Related
Communications :: Port.BytesToRead Unexpected Results?
I am writing an app in VB2005 that makes a call to my cars ECU. It sends ok but during the DataReceived event I am getting an unusual result.I am trying to find out how many bytes are in the buffer so I can set up an array to write the data to so I have used the following.

intBTR = _Port.BytesToRead
_Port.Read(bytIncoming, 0, intBTR -1)

[code]......

Posted: 09-04-2007

View 3 Replies!   View Related
[2005] Unexpected Results With FileSystem.GetFiles
Consider the following snippet:
Dim Arext() = {"*.ttf","*.ttc"}
For Each foundFile In FileSystem.GetFiles(srcdir, SearchOption.SearchTopLevelOnly, arExt)

[code]....

The unexpected result is that not all the files specified in arext() are returned by this code. Running the same code twice on the same subset of files does NOT produce consistent results.I'm seeing, probably, 90% of the files with the other 10% not being included?

Posted: Feb 20th, 2009

View 1 Replies!   View Related
C# - Lambda Expression: CS To .Net?
I am dumb founded at this statement....maybe its just too many hours/days of doing C# to VB.Net conversion but i am drawing a blank on this conversion.

List<string> sColors = new List<string>(this.CustomPaletteValues.Split(','));
try {
List<Color> colors = sColors.ConvertAll<Color>(s => (Color)(new ColorConverter().ConvertFromString(s)));

What i have so far:

Dim colors As List(Of Color) = sColors.ConvertAll(Of Color)(....)

As you can see its the content of the lambda that i am hitting a brick wall with.

Posted: Aug 24 11 at 22:18

View 3 Replies!   View Related
.net - Convert C# Lambda Expression To VB?
In looking at Fuzzy Date Time Picker Control in C# .NET? Piotr Czaapla's answer to that question is exactly what I need. unfortunately, I'm a VB.NET guy and I'm not that familiar with lambda expresions, so my attempts to convert the code have resulted in hours of misplaced parenthesis and banging my head with a brick.

Any chance some bi-lingual wizard could convert the C# code to VB.net for me?

[Code]...

Posted: Mar 23 at 13:15

View 3 Replies!   View Related
.Net Lambda Expression With No Intellisense?
Using lambda's in VB.Net results in no intellisense. Is this a bug with VS2010 or expected? Note that it works fine in C#

Return Array.TrueForAll(chequeColl, Function(x) x.Number <> "N") 'No intellisense Number does not appear
Return Array.TrueForAll(chequeColl, Function(x As MyClass) x.Number <> "N") 'Now casted intellisense appears

UPDATE: Here's an example

Public Class Cheque
Public Property Id As String
Public Property Status As Byte

[code]....

Posted: Mar 9 11 at 14:50

View 1 Replies!   View Related
Convert C# Lambda += Expression To VB?
How should the following C# code be converted to VB.Net? I have tried several code converters and none produce correct results.

[code]...

Posted: February 15, 2011

View 4 Replies!   View Related
Converting A C# Lambda Expression?
I will probably sound like a bad developer here, but I am attempting to convert some code from the following page from C# to VB.NET:The code I am having trouble converting is from Step 4 of "Joining a Multicast Group" on the page, and here is the code with the comment lines removed:

private void Join()
{
_receiveBuffer = new byte[MAX_MESSAGE_SIZE];

[code].....

Posted: 12-15-2011

View 1 Replies!   View Related
Extract The Lambda From An Expression?
I want to implement this function:

Public Function GetFunc(Of TSource, TResult) _
selector As Expression(Of Func(Of TSource, TResult)) _
As Func(Of TSource, TResult)

[code]....

UPDATE:I have the following issue, it's a part of a function:

Dim obj As Object = value
For Each exp In expressions
If obj Is Nothing Then Return [default]

[code]....

Exception Details:

ArgumentException:Object of type 'System.Linq.Expressions.Expression`1 [System.Func`3[System.Char,System.Char,System.Char]]'cannot be converted to type 'System.Func`3[System.Char,System.Char,System.Char]'.

Posted: Aug 9 10 at 7:31

View 1 Replies!   View Related
Lambda Expression Not Working?
If been try to convert some code I have from VB.net to C# but I just cannot get it working!first is the vb code I'm only interested in the line that has the Lambda Expression for the C#[code]......

Posted: 06-12-2012

View 2 Replies!   View Related
Lambda Expression Shorthand
Currently, I have code similar to this:

xxx, _
If(dr.Table.Columns.Contains("EnterpriseID"), dr.Field(Of Integer)("EnterpriseID"), -1), _
xxx

I would like to create a Lamdba expression something like the following (this doesn't work):

Dim xCol As Func(Of DataRow, String, Type, Object, Object) = _
Function(dr, x, t, dflt) _
If(dr.Table.Columns.Contains(x), dr.field(Of t)(x), dflt)

So that I can say something like:

xxx, _
xCol(dr, "EnterpriseID", GetType(System.Integer), -1), _
xxx

Posted: March 30, 2010

View 1 Replies!   View Related
Trick Lambda Expression In VB
I know in VB Lambda expressions must return a value and can only have one statement. But in my case I just need to execute a Sub that does not return a value. Is there a way to trick it by somehow returning a dummy value yet still call my Sub? If possible what would the syntax be like?

Posted: May 08, 2009

View 3 Replies!   View Related
Using The Vb Equivilant Of The MAX Lambda Expression
I am having an issue using the vb equivilant of the MAX lambda expression. at foos.Max(function(x) x.id) when I try to intellisense the property ID VS will not show it. But when i run the example it works. Is there something I am doing which is wrong, an i am just lucky it runs? [Code]

Posted: Apr 7 11 at 13:11

View 1 Replies!   View Related
VB Lambda Expression For Sub Delegate?
There is the code:

Private Sub InsertItemInCache(Of T)(ByVal item As CachedItem(Of T), ByVal dependency As AggregateCacheDependency, _
ByVal key As String, ByVal updateCallBack As CacheItemUpdateCallback)

[code].....

Posted: Nov 29 10 at 8:39

View 1 Replies!   View Related
Using The Iteration Variable?
Is the warning I am receiving about using the iteration variable in this line a concern.

Dim reportdataforpage = (From reportvar In reportdata Where reportvar.reportpage = pagenum)

Posted: Jan 23rd, 2012

View 5 Replies!   View Related
Creating A Lambda Expression With Delegate?
I am Creating a Lambda Expression, but it' not getting me the write Out put :

Public Class Form1
Delegate Function GetLastChar(ByVal S As String) As String
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

[code]....

I want Send a Name like "Arindam" and its return me "m", the last character.but in messagbox return value shows "fasle" I can't under stand why it's showing "False" instead of"m", the last character.

Posted: July 16, 2010

View 3 Replies!   View Related
Delegate Not Working Instead Of Lambda Expression
I am having a generic ListOf-collection holding the self-created User-object, I can filter for users by using lambda-expression like this:
Dim reviewers As List(Of User) = users.Where(Function(u) u.DvRoleID = 2).ToList

Instead of using the lambda expression I can also write the function and call it as argument like this:
Public Function GetReviewer1(ByVal u As User) As Boolean
If u.DvRoleID = 2 Then
Return True
[Code] .....

Now the question: why can't I create a delegate having the same signature as the GetReviewer1 function and use the delegate as argument inside the where-clause like this:
Delegate Function Criteria(ByVal u As User) As Boolean
Public Function GetReviewer1(ByVal u As User) As Boolean
If u.DvRoleID = 2 Then
[Code] .....
The compiler does not accept the crit delegate as argument.

Posted: May 14, 2010

View 3 Replies!   View Related
Getting Exports From Container In MEF (Lambda Expression)
I am trying to see if the controller class name is the name of the controller name passed in. I think my lambda expression is wrong and that is why it isn't working properly. I am passing in the correct controller names, but the export variable is always null.

Public Function CreateController(requestContext As System.Web.Routing.RequestContext,
controllerName As String)

[Code].....

Posted: Jun 22 at 13:33

View 1 Replies!   View Related
Lambda Expression And Validity Of Delegates
In MSDN documentation defination about lambda expression is "A lambda expression is a function or subroutine without a name that can be used wherever a delegate is valid ". Here validity of delegate is necessery only when we are passing lambda expression as an argument to a method.

[Code]...

Posted: May 06, 2010 03:22 AM

View 1 Replies!   View Related
Lambda Expression With Ternary Operator In VB?
Lambda expression with ternary operator in VB?

Posted: February 26, 2010

View 15 Replies!   View Related
Linq - Examples Of .NET Lambda Expression?
Where can I find complex LINQ examples made using VB.NET Lambda Expression syntax?During my searches I always found 101 LINQ Samples but they use the other notation and for me is not always clear how to transform that code into a lambda expression.

Posted: Feb 3 11 at 8:55

View 1 Replies!   View Related
Make Lambda Expression Dynamically?
In Entity Framework I usually do something like:

modelBuilder.Entity(Of Model).HasKey(Function(item As Model) New With {item.PropertyA, item.PropertyB })

to map a composite primary key

I need to write a generic function like[code]....

Posted: Jul 13 11 at 22:43

View 1 Replies!   View Related
Use A Function Both Directly And As A Lambda Expression?
Should I be concerned about the performance of the Compile method here?[code]...

The reason I want the lambda expression is because I want that function to be able to get all the way through LINQ-to-SQL to be converted to SQL. The reason I want the direct version is because I have other code that I want to validate individual serial numbers before submitting changes. And I fear that GetValidSerialNumbers.Contains(serialNumber) will execute a more-complex-than-necesssary query.

Posted: Apr 24 at 16:12

View 1 Replies!   View Related
Use Lambda Expression Within ASP.NET MVC View Using Program?
With ASP.NET MVC 1.0, .NET 3.5 and C# you can easily pass a method a lambda expression that will do a "Response.Write" some content when it's executed within the method[code]...

Posted: Oct 28 09 at 16:51

View 1 Replies!   View Related
VS 2008 - Convertion Of C# And Lambda Expression To .net
is there any perfect tool of converting C# and lambda expressions into vb.net code.

Posted: Feb 1st, 2010

View 9 Replies!   View Related
VS 2010 Lambda Expression Confusion
I've been wondering about lambda expressions for a while now.Consider the following code..[code]But in the lambda expression I have access to all Sub Main's variables.

Posted: Sep 21st, 2011

View 3 Replies!   View Related
Why Do Simple Math Operations On Floating Point Return Unexpected (inaccurate) Results In .Net And Python
x = 4.2 - 0.1
vb.net gives 4.1000000000000005
python gives 4.1000000000000005
Excel gives 4.1
Google calc gives 4.1

What is the reason this happens?

Posted: Oct 20 09 at 14:25

View 4 Replies!   View Related
Copyright 2005-08 www.BigResource.com, All rights reserved