Search Results

Search found 2455 results on 99 pages for 'lambda expressions'.

Page 4/99 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • How with lambda function in MVC3

    - by doogdeb
    I have a model which contains view models for each view. This model is held in session and is initialised when application starts. I need to be able to populate a field from one view model with the value from another so have used a lambda function. Below is my model. I am using a lambda so that when I get Test2.MyProperty it will use the FunctionTestProperty to retrieve the value from Test1.TestProperty. public class Model { public Model() { Test1 = new Test1() Test2 = new Test2(FunctionTestProperty () => Test1.TestProperty) } } public class Test1 { public string TestProperty { get; set; } } public class Test2 { public Test2() : this (() => string.Empty) {} public Test2(Func<string> functionTestProperty) { FunctionTestProperty = functionTestProperty; } public Func<string> FunctionTestProperty { get; set; } public string MyProperty { get{ return FunctionTestProperty() ?? string.Empty; } } } This works perfectly when I first run the application and navigate from Test1 to Test2; I can see that when I get the value for MyProperty it calls back to Model constructor and retrieves the Test1.TestProperty value. However when I then submit the form (Test2) it calls the default constructor which sets it to string.Empty. So if I go back to Test1 and back to Test2 again it always then calls the Test2 default constructor. Does anyone know why this works when first running the application but not after the view is submitted, or if I have made an obvious mistake?

    Read the article

  • Lambda expressions as CLR (.NET) delegates / event handlers in Visual C++ 2010

    - by absence
    Is it possible to use the new lambda expressions in Visual C++ 2010 as CLR event handlers? I've tried the following code: SomeEvent += gcnew EventHandler( [] (Object^ sender, EventArgs^ e) { // code here } ); It results in the following error message: error C3364: 'System::EventHandler' : invalid argument for delegate constructor; delegate target needs to be a pointer to a member function Am I attempting the impossible, or is simply my syntax wrong?

    Read the article

  • C++ boost::lambda::ret equivalent in phoenix

    - by aaa
    hello. Boost lambda allows to overwrite deduced return type using ret<T> template. I have tried searching for equivalent in phoenix but could not find one. Is there an equivalent in phoenix? I know how to make my own Replacement but I would rather not. thank you

    Read the article

  • Convert this Linq query from query syntax to lambda expression

    - by Jinkinz
    I'm not sure I like linq query syntax...its just not my preference. But I don't know what this query would look like using lambda expressions, can someone help? from securityRoles in user.SecurityRoles from permissions in securityRoles.Permissions where permissions.SecurableEntity.Name == "Unit" && permissions.PermissionType.Name == "Read" orderby permissions.PermissionLevel.Value descending select permissions There is a many-to-many relationship between users and security roles that makes this extra confusing. Thanks! Kelly

    Read the article

  • To Reference A Generic Method With A Lambda Expression

    - by SDReyes
    It is possible to reference a generic method using a Lambda Expression Object? For example, having: TheObject: public abstract class LambdaExpression : Expression TheMethod (an extension method of LINQ): public static TSource Last<TSource>( this IEnumerable<TSource> source ) I'm trying to create an instance of TheObject, that references to TheMethod. How do you do such thing?

    Read the article

  • Rewriting a statement using LAMBDA(C#)

    - by Thinking
    Is it possible to write the folowing using lambda(C#) private static void GetRecordList(List<CustomerInfo> lstCustinfo) { for (int i = 1; i <= 5; i++) { if (i % 2 == 0) lstCustinfo.Add(new CustomerInfo { CountryCode = "USA", CustomerAddress = "US Address" + i.ToString(), CustomerName = "US Customer Name" + i.ToString(), ForeignAmount = i * 50 }); else lstCustinfo.Add(new CustomerInfo { CountryCode = "UK", CustomerAddress = "UK Address" + i.ToString(), CustomerName = "UK Customer Name" + i.ToString(), ForeignAmount = i * 80 }); } }

    Read the article

  • Lambda Expressions and Memory Management

    - by Surya
    How do the Lambda Expressions / Closures in C++0x complicate the memory management in C++? Why do some people say that closures have no place in languages with manual memory management? Is there claim valid and if yes, what are the reasons behind it?

    Read the article

  • Correct use of boost lambda

    - by Niels P.
    Consider the following piece of C++0x code: a_signal.connect([](int i) { if(boost::any_cast<std::string>(_buffer[i]) == "foo") { base_class<>* an_object = new derived_class(); an_object->a_method(_buffer[i]); }}); How would it correctly look in Boost Lambda (since this C++0x feature can't be used yet)?

    Read the article

  • using lambda instead of let in scheme

    - by Radagaisus
    Hey, In SICP 1.2.1 there is a function that makes a rational number, as follow: (define (make-rat n d) (let ((g (gcd n d))) (cons (/ n g) (/ d g)))) I'm just curious how you can implement the same thing using lambda instead of let, without calling GCD twice. I couldn't figure it out myself.

    Read the article

  • Lambda functions

    - by Oden
    Hey, I'm really interested in the way of using lambda functions. Does it make sense to use them in a high-level programming language? If yes, why? Is this really just a function embedded in a function (like this) or is there more behind?

    Read the article

  • Lambda recursive PHP functions.

    - by Kendall Hopkins
    Is it possible to have a PHP function that is both recursive and anonymous (lambda). This is my attempt to get it to work, but it doesn't pass in the function name. $factorial = function( $n ) use ( $factorial ) { if( $n == 1 ) return 1; return $factorial( $n - 1 ) * $n; }; print $factorial( 5 ); I'm also aware that this is a bad way to implement factorial, it's just an example.

    Read the article

  • Perfect Forwarding to async lambda

    - by Alexander Kondratskiy
    I have a function template, where I want to do perfect forwarding into a lambda that I run on another thread. Here is a minimal test case which you can directly compile: #include <thread> #include <future> #include <utility> #include <iostream> #include <vector> /** * Function template that does perfect forwarding to a lambda inside an * async call (or at least tries to). I want both instantiations of the * function to work (one for lvalue references T&, and rvalue reference T&&). * However, I cannot get the code to compile when calling it with an lvalue. * See main() below. */ template <typename T> std::string accessValueAsync(T&& obj) { std::future<std::string> fut = std::async(std::launch::async, [](T&& vec) mutable { return vec[0]; }, std::forward<T>(obj)); return fut.get(); } int main(int argc, char const *argv[]) { std::vector<std::string> lvalue{"Testing"}; // calling with what I assume is an lvalue reference does NOT compile std::cout << accessValueAsync(lvalue) << std::endl; // calling with rvalue reference compiles std::cout << accessValueAsync(std::move(lvalue)) << std::endl; // I want both to compile. return 0; } For the non-compiling case, here is the last line of the error message which is intelligible: main.cpp|13 col 29| note: no known conversion for argument 1 from ‘std::vector<std::basic_string<char> >’ to ‘std::vector<std::basic_string<char> >&’ I have a feeling it may have something to do with how T&& is deduced, but I can't pinpoint the exact point of failure and fix it. Any suggestions? Thank you! EDIT: I am using gcc 4.7.0 just in case this could be a compiler issue (probably not)

    Read the article

  • Restrictons of Python compared to Ruby: lambda's

    - by Shyam
    Hi, I was going over some pages from WikiVS, that I quote from: because lambdas in Python are restricted to expressions and cannot contain statements I would like to know what would be a good example (or more) where this restriction would be, preferably compared to the Ruby language. Thank you for your answers, comments and feedback!

    Read the article

  • check that int array contains !=0 value using lambda

    - by netmajor
    hey, I have two-dimension array List<List<int>> boardArray How can I enumerate throw this array to check that it contains other value than 0 ? I think about boardArray.Contains and ForEach ,cause it return bool value but I don't have too much experience with lambda expression :/ Please help :)

    Read the article

  • C# Lambda Expression Speed

    - by Nathan
    I have not used many lambda expressions before and I ran into a case where I thought I could make slick use of one. I have a custom list of ~19,000 records and I need to find out if a record exists or not in the list so instead of writing a bunch of loops or using linq to go through the list I decided to try this: for (int i = MinX; i <= MaxX; ++i) { tempY = MinY; while (tempY <= MaxY) { bool exists = myList.Exists(item => item.XCoord == i && item.YCoord == tempY); ++tempY; } } Only problem is it take ~9 - 11 seconds to execute. Am I doing something wrong is this just a case of where I shouldn't be using an expression like this? Thanks.

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >