I am prototyping some C# 3 collection filters and came across this.
I have a collection of products:
public class MyProduct
{
public string Name { get; set; }
public Double Price { get; set; }
public string Description { get; set; }
}
var MyProducts = new List<MyProduct>
{
new MyProduc...
Say we have the following method:
private MyObject foo = new MyObject();
// and later in the class
public void PotentialMemoryLeaker(){
int firedCount = 0;
foo.AnEvent += (o,e) => { firedCount++;Console.Write(firedCount);};
foo.MethodThatFiresAnEvent();
}
If the class with this method is instantiated and the PotentialMemoryLea...
Hey guys, I see this term being used a bit, and a Google search didn't quite yield the most clarity, so help me out: for a person without a comp-sci background, what is a lambda in the world of Computer Science?
UPDATE:
marxidad, thanks for the reply--it seems to be climbing up in everyone's favor, so I'll likely accept it soon. Do you...
Joe Van Dyk asked the Ruby mailing list:
Hi,
In Ruby, I guess you can't marshal a lambda/proc object, right? Is
that possible in lisp or other languages?
What I was trying to do:
l = lamda { ... }
Bj.submit "/path/to/ruby/program", :stdin => Marshal.dump(l)
So, I'm sending BackgroundJob a lambda object, which cont...
I've read that Lambda Expressions are an incredibly powerful addition to C#, yet I find myself mystified by them. How can they improve my life or make my code better? Can anyone point to a good resource for learning such expressions?
They seem cool as hell, but how do they relate to my day-to-day life as an asp.net developer?
Edit: Tha...
How can I do what's in the title, with the minimum amount of code, using whatever c# 3.5 syntax (I'm guessing lambda expressions would fit, but I still don't understand them fully)?
In short,
I want to iterate through all types that implement a particular interface.
Edit: I wasn't clear.
Let me re-phrase my question: How can I, using r...
Saw a post about hidden features in C# but not a lot of people have written linq/lambdas example so... I wonder...
What's the coolest (as in the most elegant) use of the C# LINQ and/or Lambdas/anonymous delegates you have ever saw/written?
Bonus if it has went into production too!
...
In C# is there a shorthand way to write this:
public static bool IsAllowed(int userID)
{
return (userID == Personnel.JohnDoe || userID == Personnel.JaneDoe ...);
}
Like:
public static bool IsAllowed(int userID)
{
return (userID in Personnel.JohnDoe, Personnel.JaneDoe ...);
}
I know I could also use switch, but there are pro...
Is it possible to pass a reference to a function to another function in F#? Specifically, I'd like to pass lambda functions like
foo(fun x -> x ** 3)
More specifically, I need to know how I would refer to the passed function in a function that I wrote myself.
...
I have a list of Foo. Foo has properties Bar and Lum. Some Foos have identical values for Bar. How can I use lambda/linq to group my Foos by Bar so I can iterate over each grouping's Lums?
...
I am new to all the anonymous features and need some help. I have gotten the following to work:
public void FakeSaveWithMessage(Transaction t) {
t.Message = "I drink goats blood";
}
public delegate void FakeSave(Transaction t);
public void SampleTestFunction() {
...
Expect.Call(delegate { _dao.Save(t); }).Do(new FakeSave(Fake...
Can someone show me how to implement a recursive lambda expression to traverse a tree structure in C#.
...
In the ContainsIngredients method in the following code, is it possible to cache the p.Ingredients value instead of explicitly referencing it several times? This is a fairly trivial example that I just cooked up for illustrative purposes, but the code I'm working on references values deep inside p eg. p.InnerObject.ExpensiveMethod().Val...
If I have an IEnumerator variable is it possible to have a lambda function that takes it, advances it with MoveNext() and returns the Current value every single time its called?
...
I get asked this question a lot and I thought I'd solicit some input on how to best describe the difference.
...
I notice that if I write
Expect.Call(delegate { obj.Method(null); }).IgnoreArguments().Do(
new Action(() => {Console.Write("executed");throw new Exception(); }));
Provided that the method does run, MbUnit will recieve the "executed" message but will not detect an exception being thrown. Does anyone know why that is so? Is this som...
Anyone got a good explanation of "combinators" (Y-combinators etc. and NOT the company)
I'm looking for one for the practical programmer who understands recursion and higher-order functions, but doesn't have a strong theory or math background.
(Note that I'm talking about these things : http://en.wikipedia.org/wiki/Y_combinator )
...
I often plug pre-configured lambdas into enumerable methods like 'map', 'select' etc.
but the behavior of 'inject' seems to be different.
e.g. with
mult4 = lambda {|item| item * 4 }
then
(5..10).map &mult4
gives me
[20, 24, 28, 32, 36, 40]
However, if I make a 2-parameter lambda for use with an inject like so,
multL = lambda {|...
With the advent of new features like lambda expressions (inline code), does it mean we dont have to use delegates or anonymous methods anymore? In almost all the samples I have seen, it is for rewriting using the new syntax.
Any place where we still have to use delegates and lambda expressions won't work?
...
So, I am using the Linq entity framework. I have to entities "Content" and "Tag" They are in a many-to-many relationship with one another. Content can have many tags and Tags can have many Contents. So I am trying to write a query to select all contents where any tags names are equal to "blah."
The entities both have a collection of the...