Lambda - Type Inferencing In Lamda Expressions?

Feb 22, 2010

I have a type lets call it "MyType". I have a List(Of MyType). Here is what i'm doing: MyList.Sum(Function(x) x.MyFieldToTotal) "MyFieldToTotal" is a decimal. For the life of me i can't figure out why x above is an object rather than a type of "MyType". Shouldn't Type Inferencing be working in this case? Even in intellisense i get "selector as System.Func(Of MyType) as Decimal"

[Code]...

View 1 Replies


ADVERTISEMENT

Lamda Expressions Are Not Showing Up In Intellesence?

Nov 12, 2010

I am having an strange problem in visual studio 2010, visual basic, and using linq. My lamda expressions are not showing up in intellesence. The project I am working on was created in visual studio 2008 and I have converted it to a visual studio 2010 project.

Here is the expression I am trying to run:

ClockItemsColl.Filter = ClockItemsColl.AsQueryable().OrderBy(d >= d.Second)

However the error I am getting is:

'd' is not accessible in this context because it is 'Friend'.

I have also tried

ClockItemsColl.Filter = ClockItemsColl.AsQueryable().OrderBy(Function(d As ClockItems) d >= d.Second)

But is still generates an error and I can't make heads or tails of it.

Overload resolution failed because no accessible 'OrderBy' can be called with these arguments:
Extension method 'Public Function OrderBy(Of TKey)(keySelector As System.Func(Of BusinessObjects.ClockItems, TKey)) As System.Linq.IOrderedEnumerable(Of BusinessObjects.ClockItems)' defined in 'System.Linq.Enumerable': Operator '>=' is not defined for types 'BusinessObjects.ClockItems' and 'Integer?'.

[code]....

View 1 Replies

C# - Use Or Not Lambda Expressions?

Nov 11, 2009

I see lambda expressions have become a very useful tool at some points in the language. I've been using them a lot and most of the time they fit really nice and make the code shorter and perhaps clearer.

Now.. I've seen some , I would say excessive use of them. Some people like them so much that try to use them everywhere they can.. Some times the C# code looks like a functional language. Other factors against are the cost using reflection by lambda and that not friendly to debugging.I would like to hear opinions about how good and how code clear it is to use more or less the lambda expressions. (this is not the better example, but let's say it was the trigger)I was writing the following code. The use of the delegate { return null; } helps me avoid having to ask if the event is null or not every time I have to use it.

public delegate ContactCellInfo.Guest AddGuest();
public event AddGuest GuestRequest = delegate { return null;}

Im using resharper and the wise resharper( even it some times literaly eats the memory) made me the following suggestion

public delegate ContactCellInfo.Guest AddGuest();
public event AddGuest GuestRequest = () => null;

At my point of view the code using the delegate looks clearer. I am not against the Lamdba expression just would like to hear some advices on how and when to use them.

View 1 Replies

Lambda Expressions In C# Vs. .net?

Jan 20, 2010

Functionally, is there any difference (apart from syntax onbviously) between lambda expressions in C# and VB.Net?EDIT: following up on CraigTP's answer: any references to the situation in .Net 4?EDIT: I'm asking because I'm used to C#, but for a next project the customer asks VB.Net. We're not a priori against that. We realize that most language constructs are supported in both languages. However, we're particularly fond of the way C# implements lambda expressions. We would like to have an overview of the differences with VB.Net

EDIT: accepted CraigTP's answer for pointing out what I currently consider the most important difference.

So to summarize: VB.Net 9 does not support multiline statements in a lambda expression, and a lambda must always return a value. Both of these issues are addressed in VB.Net 10

View 5 Replies

C# - .NET Async Lambda-expressions?

Apr 20, 2012

Async Sub like this: Dim f As Func(Of Task) = Async Sub() End Sub Produces compiler error: error BC36670: Nested sub does not have a signature that is compatible with delegate 'System.Func(Of System.Threading.Tasks.Task)'.Equivalent C# code compiles fine:

Func<Task> f = async () => { };Rewriting Async Sub into Async Function make code works.

Why does Async Sub() is not convertible to delegate types with return value of type Task?

View 1 Replies

Converting Lambda Expressions To .net?

Jul 4, 2010

how to convert this code to VB.net, can anybody help?

public static readonly DependencyProperty CommandProperty =
DependencyProperty.RegisterAttached(
"Command",

[code]...

View 1 Replies

Sum The Counts With Lambda Expressions

Feb 3, 2012

I have a List(of T) where T has a property that is a list of checkboxes, what I need is a Lambda expression that will count all the checked checkboxes in the list. I tried with:

[Code]...

View 5 Replies

Why Do Lambda Expressions In VB Differ From C#

Jul 19, 2011

I just came across a bug in NHibernate which happens to already be raised: [url] I'm not sure if this applies to anything else other than enums but when using a Lambda from VB, it looks different to the same Lambda from C#.

C#:

Where(x => x.Status == EmployeeStatus.Active)

VB

Where(Function(x) x.Status = EmployeeStatus.Active)

They are the same as far as I'm aware? (My VB isn't great) If I put a break point on the same line of code, where the above code is passed into. In C# I get: On the same line when VB version is passed in, I get: Is this something I'm doing wrong? Is the result's the same, just displayed different between C#/VB?

Edit: Ok so they are displayed different, but they can't be the same because NHibernate cannot handle it. The C# version is handled perfectly fine by NHibernate, the VB version resolves in the following exception being thrown: [Code]

View 3 Replies

.net - MSBuild Fails On Lambda Expressions?

Jul 25, 2011

I have an issue with building a project using the MSBuild (ver 4) from the command line when declaring lambda expression like this:

Private Sub Foo(ByVal s As String)
Dim WL = Sub(str As String)
If Not String.IsNullOrEmpty(str) Then[code]......

View 1 Replies

Background Info For Lambda Expressions?

Mar 6, 2009

I'm trying to expand my programming horizons, and LINQ and Lambda Expressions have popped up as some apparently very important topics. As I began reading articles on Lambda Expressions, it appears that Lambda Expressions are built heavily on the concept of Delegates. As I began reading articles on Delegates, it appears that Delegates are built heavily on the concept of callback functions. As I began reading articles on callback functions, .[code]Can anyone out there give me a simple, clear, concise definition of callback functions? Do I need to learn C or C++ to fully understand these concepts? Maybe a better question is: What do I need to know to be able to understand Delegates (they've always somewhat mystified me) and LINQ/Lambda Expressions (I haven't looked into these too much, but they're mystifying, too)?I don't mind doing research, but google searches are giving me way too much information.

View 4 Replies

How Are The Lambda Expressions Related To The Delegates

Jul 7, 2010

what are delegates?How are the lambda expressions related to the delegates?

reading the msdn about the delegates is really confusing me ;so i need a start off from here before moving on to the msdn.

View 27 Replies

VS 2010 RemoveHandler With Lambda Expressions?

Jul 1, 2011

To streamline code, I increasingly rely on lambda expressions. But I may have hit against the wall in the attempt of removing an event handler set by a lambda expression. This really eludes me. The code below shows two samples: Alt1 uses a plain lambda expression as delegate and works fine: the object size increases as the numeric control varies. However, the drawback is that the handler cannot be removed:

RemoveHandler Me.upDnScale.ValueChanged, Sub(sender As Object, e As Object) ScaleObject1(sender, e, objTgt)
According to this MSDN article, a variable should be used to set/remove lambda based handlers. Alt2 shows a couple of attempts, but none works.

[Code]...

View 1 Replies

Lambda Expressions With Multiple Search Criteria?

May 21, 2012

Currently I am searching through my list to find Customers that match on Address.
I need to match on both address and city. How do I rewrite my lambda Expression to match both criteria?

CustomerList.FindAll(Function(c) c.Address = addressToMatch)

View 1 Replies

Remove Handler Setup By Lambda Expressions?

Jul 2, 2011

How to remove a handler set up by a lambda expression? According to this MSDN article, lambda expression should be assigned to variables which should be used to define handler operators. So far, I have used lambda expessions w/o variables.

For instance, the following works:
Private Sub ScaleObjectInit1(ByVal objSrc As NumericUpDown, ByVal objTgt As FrameworkElement) ...
AddHandler Me.upDnScale.ValueChanged, Sub (sender As Object, e As Object) ScaleObject1 (sender, e, objTgt)
End Sub
Private Sub ScaleObject1(ByVal sender As Object, ByVal e As Object, ByVal objTgt As FrameworkElement)
[Code] .....

View 3 Replies

IDE :: Crash VS2010 IDE By Mixing Lambda Expressions With SyncLock?

Jun 30, 2011

Can someone who is using a 64 bit machine help me pintpoint this crash to either the VS2010 IDE itself or one of the plugins I have installed?

It's the code fragment below. When I copy & paste it into the Main() function of a new VB.Net console app on my Win7 64 bit machine, the VS IDE crashes and dies onthe spot, every time I try it.

Doing exactly the same on a 32 bit XP machine, nothing abnormal happens.

The 64 bit machine does have some IDE plug-ins installed, the biggest of which is DevExpress (the free version), so i think either one of those or the fact that the IDE is running on 64 bit must be the culprit.

This is the code. The static variable can also be made a module-level variable, with the same result.

View 2 Replies

Linq - Order By Multiple Columns Using Lambda Expressions

Nov 16, 2009

I'm still trying to get my head around the whole "Lambda Expressions" thing.

Can anyone here give me an example ordering by multiple columns using VB.Net and Linq-to-SQL using a lambda expression?

Here is my existing code, which returns an ordered list using a single-column to order the results:

Return _dbContext.WebCategories.OrderBy(Function(c As WebCategory) c.DisplayOrder).ToList

Note: The WebCategory object has a child WebPage object (based on a foreign key). I'd like to order by WebPage.DisplayOrder first, then by WebCategory.DisplayOrder.

I tried chaining the order bys, like below, and though it compiled and ran, it didn't seem to return the data in the order I wanted.

Return _dbContext.WebCategories.OrderBy(Function(c As WebCategory) c.DisplayOrder).OrderBy(Function(c As WebCategory) c.WebPage.DisplayOrder).ToList

View 2 Replies

VB Dynamic Run-Time Query With Linq And Lambda Expressions

Mar 16, 2009

I have an untyped dataset returned from my WebService. The user wants to dynamically construct a query referencing tables and columns and specifying values to test for.I have looked at Lambda Expressions and the Expressions.Expression Namespace. I think these provide the answer I'm looking for, but I'm not certain how to go about contructing the linq expressions to extract the datarows I'm looking for.

I plan on limiting the result to one datatable that the query will result in and i"ll provide the joins from the user's constructs.For a simple example I have a DataTable with (n) rows called "Table", and in it there is a computed column called "b_IsActive" that has the expression "Convert(IsActive, 'System.Boolean')". The user wants to retrieve all rows in "Table" where field "b_IsActive" is true.

View 5 Replies

Book Recommendation With Good Lambda Expressions And LINQ Chapters?

May 20, 2009

I'm looking for an advanced level VB.NET book which covers LINQ and Lambda Expressions.Generally I read C# .NET books due to lack of good VB.NET books when it comes to generic .NET Framework related subjects. However Lambda and LINQ is quite different in C# and VB.NET I'm looking for an advanced level VB.NET book on this subjec

View 1 Replies

C# - Solve This Error "Cannot Convert Lambda Expression To Type 'string' Because It Is Not A Delegate Type"

Jun 12, 2010

. I get this error: "Cannot convert lambda expression to type 'string' because it is not a delegate type" - keyword select become underlined in blue

[Code]...

Above code should displays drop list of employees first name and last name in a combo box

View 2 Replies

Asp.net - Reference Property Of An Unknown Type In Lambda Function

May 18, 2011

I'm trying to create a generic function to build a Linq expression from a list of Telerik grid filters. I'm trying to stay clear of dynamic Linq. Because I don't know the type that I'm building the expression for, I'm attempting to use reflection in the lambda functions to refer to a property, but after applying the fix suggested by @JaredPar I get the error, "The LINQ expression node type 'Invoke' is not supported in LINQ to Entities." Is there any way around this? here is my code:

Public Shared Function buildRadFilter(Of T)(ByVal filterExpression As List(Of GridFilterExpression)) As Expressions.Expression(Of Func(Of T, Boolean))
Dim returnPred = PredicateBuilder.True(Of T)()

[Code]....

View 1 Replies

Lambda Coding - Basic Code Of Lambda With Explanation

Jun 21, 2011

Im hearing about this, can someone explain it to me or please show some basic code of Lambda with explanation.

View 2 Replies

Lambda Tutorial And Solving A Lambda-Function

Dec 14, 2009

Is it possible to shorten the following function to a lambda expression?Or (to do the trick by myself) what is the best and most understandable for beginners tutorial for lambda in vb.net?[code]

View 2 Replies

Ombine Two Linq Expressions Of A Custom Type (i.e. Expression(Of Func(Of MyClass, MyClass))

Nov 24, 2010

I have a list of properties and values that i'd like to use to dynamically build an Expression(Of Func(Of MyClass,MyClass))

I can run through the list and create each Expression by itself, but the only way I know how to combine them would be to use Expression.And or Expression.AndAlso, but that returns a BinaryExpression rather than my original Expression(Of Func(Of MyClass,MyClass)).

View 1 Replies

Can't Seem To Make The Lamda Expression Work?

Aug 12, 2010

I'm trying to convert a function in C# to VB.Net 2008 and can't seem to make the Lamda expression work. The code is taken from a neat little C# SMTP server that saves emails to Azure blob storage

[Code]...

View 3 Replies

Check Whether Lamda Expressioin Parameters Are Nullable?

Aug 31, 2011

typeof(Nullable<>)
public static bool IsNullableType(Type t)
{
return t.IsGenericType && t.GetGenericTypeDefinition() == typeof(Nullable<>);
}

I was using this to check whether Lamda Expressioin parameters are nullable.

View 3 Replies

How To Get Lamda In LINQ To Actually Filter For Dynamic Linq

Sep 10, 2009

Example-I have a person class

Public Class Person
Private _fname As String
Public Property Fname() As String

[Code]...

View 2 Replies

Evaluate All The Expressions?

Jan 4, 2010

if i do not need to evaluate all the expressions, am i right to say that there are benefits and no disadvantages of using AndAlso compared to using And

example:

if a=b And f=g And y=k
can be better done with:
if a=b AndAlso f=g AndAlso y=k

View 22 Replies

NET 8 - Add General Expressions?

Apr 25, 2012

I wish to incorporate general expressions in my Visual Basic work.Other than the basic inputting "Imports System.Text.RegularExpressions", I have no idea how to do put general expressions in my VB project.However, I can create the expressions (so, all is not lost).

View 1 Replies

.net - Are These Expressions True Or False

Feb 20, 2011

The expression 3>6 AndAlso 7>4 evaluates to
A. True B. False
The expression 4>6 OrElse 10<2*6 evaluates to
A. True B. False
The expression 7>=3+4 OrElse 6<4 AndAlso 2<5 evaluates to
A. True B. False

View 4 Replies

C# - Regular Expressions For Class Name?

Jan 15, 2011

i need a regular expressions string to get all anchor tags in a page with a specific css class name, in c#/vb.netthis is what i got so far"<a.*?href=""(.*?)"".*?>(.*?)</a>"ut my attempts to add "class=name" isnt working, also is it possible to find links where the class name appears either before or after the href with one expression

View 4 Replies







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