anonymous function usefulness
Why not write the anonymous function content only instead of the anonymous function AND the anonymous function content? ...
Why not write the anonymous function content only instead of the anonymous function AND the anonymous function content? ...
I know it's not executed immediatly, but then when? ...
code 1 $(document).ready(function() { $('.poem-stanza').addClass('highlight'); }); code 2 $(document).ready( $('.poem-stanza').addClass('highlight'); ); ...
The method below called UserCanAccessThisPage is based on the following logic: each user and each page has a list of groups. If any of these match, the user has access to the page. The code below does what I want, but my solution is very C# 1 (or C# 2, at least I didn't use ArrayList). Can anyone refactor this so it is more straight-fo...
I have tables Users, Widgets and Layouts. Users have many-to-many relationship with Widgets via Layouts. Each Layout has UserID and WidgetID. I want to delete a Layout that matches specific UserID and WidgetID. Using SubSonic 3 ActiveRecord I write: Layout.Delete(x => x.UserID == user.id && x.WidgetID == id); However, SubSonic delete...
Would it work to use Expression<Func<T>> or Func<T> as keys in a dictionary? For example to cache the result of heavy calculations. For example, changing my very basic cache from a different question of mine a bit: public static class Cache<T> { // Alternatively using Expression<Func<T>> instead private static Dictionary<Func<T...
I'd like to merge the following Expression: // example class class Order { List<OrderLine> Lines } class OrderLine { } Expression<Func<Order, List<OrderLine>>> selectOrderLines = o => o.Lines; Expression<Func<List<OrderLine>, Boolean>> validateOrderLines = lines => lines.Count > 0; // now combine those to Expression<Func<Or...
I'm sure I have seen this syntax <%= Url.Action((MyController c) => c.MyMethod("a")) %> or something like it as a way to generate action URLs in ASP.net MVCs without magic strings. However, I can't find that Action overload. I have ASP.NET MVC 1.0. Where is it? ...
So I wrote this simple console app to aid in my question asking. What is the proper way to use a lambda expression on line 3 of the method to get the common members. Tried a Join() but couldn't figure out the correct syntax. As follow up... is there a non-LINQ way to do this in one line that I missed? class Program { static void Mai...
I'm curious to know whether a Lambda (when used as delegate) will create a new instance every time it is invoked, or whether the compiler will figure out a way to instantiate the delegate only once and pass in that instance. More specifically, I'm wanting to create an API for an XNA game that I can use a lambda to pass in a custom call ...
Lets say I have two classes: class A { [SortOrder(3)] public string Name { get; set; } } class B : A { [SortBefore(*****)] public string Age { get; set; } } Note the stars in the property attribute in the second class. Would it somehow (using expressions I guess) be possible to specify A.Name in the SortBefore attribute? ...
my method: public TableFilled<TKey, TRow> getTera() { Func<TablesFilled<TKey,TRow>> _getTera=new Func<TablesFilled<TKey,TRow>>( ()=>{return (TablesFilled<TKey,TRow>) chGetTera();}); //Above does not compile says: Cannot convert type //'AcapsVerify.FunctionalTables.TableFilled<TKey,TRow>' to //'AcapsVerify.F...
Not that I would want to use this practically (for many reasons) but out of strict curiousity I would like to know if there is a way to reverse order a string using LINQ and/or LAMBDA expressions in one line of code, without utilising any framework "Reverse" methods. e.g. string value = "reverse me"; string reversedValue = (....); an...
Do you know a Visual Studio 2008 Addon, which allows the debugging of Lambda expressions (in the Watch window)? ...
I'm beginning to program in C# 2.0, so I have never used lambda expressions, but, why so much fuss about it? Are them just syntactic sugar around anonymous delegates, or is there something more which I can't see? ...
If I have Visual Studio 2008 and I target a .NET 2.0 application, can I still use Lambda Expressions? My understanding of Lambda Expressios is that its a feature built into the compiler, not the framework, so my conclusion would be that I could use Lambda in .NET 2.0 application. Can someone please tell me if this is so? ...
Hi, I am attempting to select from a List using a linq expression where the range variable is evaluated in a static method that returns boolean. I would like to select the range variable that returns true when the range variable is evaluated using the method. var result = from rangeVariable in DataSource where (rangeVariab...
Just tooling around for my own amusement, and I want to use a lambda, because I feel like it. Can I replace this function with a lambda? def isodd(number): if (number%2 == 0): return False else: return True Elementary, yes. But I'm interested to know... ...
class TreeNode { public string Value { get; set;} public Collection<TreeNode> Nodes { get; set;} public TreeNode() { Nodes = new Collection<TreeNode>(); } } 1) How would you write the recursive lambda expression to return the TreeNode with a particular value (or null if not found) assuming the values are u...