lambda

How to display data from XML file to ListView using LINQ to XML?

I'm having an xml file like <Root> <Child val1="1" val2="2"/> <Child val1="1" val2="3"/> <Child val1="2" val2="4"/> </Root> i need to display the data from the Xml file to a Listview like (Added A to index value) Now i'm using like 1.Stores the data in an XmlNodesList 2.Then iterate through the nodeslist and add the attribut...

.NET 3.5: anonymous delegate for handlers with ref params

I have public delegate void DocumentCompleteEventHandler(object pDisp, ref object URL) Can i use lambda expression such as : ie.DocumentComplete += (o, e) => { }; It expression doesn't work. How should i change it for using in code? Is it possible? ...

How to store delegates in a List

How can I store delegates (named, anonymous, lambda) in a generic list? Basically I am trying to build a delegate dictionary from where I can access a stored delegate using a key and execute it and return the value on demand. Is it possible to do in C# 4? Any idea to accomplish it? Note : Heterogeneous list is preferable where I can stor...

Get value from ASP.NET MVC Lambda Expression

Hi, I am trying to create my own HTML Helper which takes in an expression (similar to the built-in LabelFor<> helper. I have found examples to obtain the value of a property when the expression is similar to this: model => model.Forename However, in some of my models, I want to obtain properties in child elements, e.g. model => mode....

Lambda and VB.NET

Hello, I have found this example on StackOverflow: var people = new List<Person> { new Person{Name="aaa", Salary=15000, isHip=false} ,new Person{Name="aaa", Salary=15000, isHip=false} ,new Person{Name="bbb", Salary=20000, isHip=false} ,new Person{Name="ccc", Salary=25000, isHip=false} ,new Person{Name="ddd", Salary=...

How do delegate/lambda typing and coercion work?

I've noticed some examples of things that work and don't work when dealing with lambda functions and anonymous delegates in C#. What's going on here? class Test : Control { void testInvoke() { // The best overloaded method match for 'Invoke' has some invalid arguments Invoke(doSomething); // Cannot convert ...

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 and then it comes the warning "Using the iteration variable in a lambda expression may have unexpected results. Instead, create a local variable within the loop and assign it the...

Building expression tree to dynamically sort a dictionary of dictionaries in LINQ

Hi All, I am attempting to dynamically build up an expression tree so that I can change the sort order for data contained in a dictionary of dictionaries. There is lots of information about dynamically specifying the column to sort by, but this is not really the part I am having problems with. I am struggling with the MethodCallExpressi...

Linq - 'Saving' OrderBy operation (c#)

Assume I have generic list L of some type in c#. Then, using linq, call OrderBy() on it, passing in a lambda expression. If I then re-assign the L, the previous order operation will obviously be lost. Is there any way I can 'save' the lambda expression I used on the list before i reassigned it, and re-apply it? ...

Interview Question: What is Lambda expression?

I have had recently two telephone interviews. In both of them I have been asked what is Lambda expression as the last question. Well I said that Lambda expression is an unnamed method in place of a delegate. But somehow that wasn't enough. I find it very hard to explain this precisely on a telephone interview. Does anyone know bet...

LINQ Lambda - Find all ID's in one list that don't exist in the other list

I have two collections of objects (List list1 and List list2). There is a property on each called "ID". I know that list2 will always have more items than list1, I just need an easy way to get a collection of all the items that exist in list2 but not list1 using LINQ lambda expressions. ...

VB.NET Using a custom timer in a lambda expression in its own "New" statement - is it okay?

This works, and I can't imagine how it might cause problems, but visual studio gives me an warning and that makes me sad. I'm just wondering if doing something like this might ever cause problems: I have a custom timer that acts like a Wait for some number of milliseconds and then execute a function. It looks like this: Public Class ...

C#: How to manipulate List<String> using LINQ or LAMBDA expression

i'm having a List<String> like List<String> MyList=new List<String> { "101010", "000000", "111000" }; I need to create a new list (List<String>) with "MyList" . so the rows in the "MyList" becomes columns in the new List and the columns become rows So the result will be like { "101", "001", "101", ...

Sorting a set<string> on the basis of length

My question is related to this. I wanted to perform a sort() operation over the set with the help of a lambda expression as a predicate. My code is #include <set> #include <string> #include <iostream> #include <algorithm> int main() { using namespace std; string s = "abc"; set<string> results; do { for (int n = 1; n <= s....

How to get child property inside parent class?

Hi all, Could you answer me how to do next, please? How to do this with Lambda? Is it possible to delegate some object instance and use its properties and methods in case if this method doesn't know type of delegated object? class class_a { public string getChildData<T> (T dynamicInstance) { return dynamicInstance.prop; ...

Why does my Lambda query return an anonymous type versus Linq's strongly-typed return value?

Ok, bear with me... hadn't done any Linq or Lambda until a couple of days ago :) I'm using C# and the ADO.NET Entity Framework. I want to query my model and get back a List of objects based on a relationship. Here's my code: var query = db.Achievements.Join ( db.AchievementOrganisations, ach => ach.AchievementId, ao => ao.Achieve...

How to convert this SQL query to LINQ or Lambda expression?

Hi every one, I have the following SQL query: SELECT C.ID, C.Name FROM Category C JOIN Layout L ON C.ID = L.CategoryID JOIN Position P ON L.PositionID LIKE '%' + CAST(P.ID AS VARCHAR) + '%' WHERE P.Code = 'TopMenu' and following data Position: ID Code 1 TopMenu 2 BottomMenu Category ID Name 1 Home 2...

Unresolved lambda expression in Re#

I can't figure out what Re# is complaining about with a piece of code. Everything compiles ok and works as it should, but Re# can't seem to resolve the expression without offering any suggestions. Look at the attachment for code and error. Any offers? ...

Why can't I create the same Expression Tree manually that my straight lambda produces

I've gone through and beat my head against the wall for a while now searched on various phrases and keywords but I cannot find anything close to an answer so i'm hoping someone here can shed some light. Basically I'm working on diving pretty deep into manipulating, creating, and modifying Expression Trees in C# 4.0 I came across an odd...

Refactor this code

I am trying to populate a tree view based on a list of staff from various deparments (lstStaff). public class Staff { public int StaffID { get; set; } public string StaffName { get; set; } public int DeptID { get; set; } public string DepartmentName { get; set; } } The result should be like this: Department A John D...