Expressions lambda. Delegate int del(int i); static void Main(string[] args) { del myDelegate = x => x * x; int j = myDelegate(5); //j = 25 } using System.Linq.Expressions; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { Expression<del> myET = x => x * x; } } } (input parameters) => expression (int x, string s) => s.Length > x (input parameters) => {statement;} delegate void TestDelegate(string s); … TestDelegate myDel = n => { string s = n + " " + "World"; Console.WriteLine(s); }; myDel("Hello"); public partial class Form1 : Form { public Form1() { InitializeComponent(); } private async void button1_Click(object sender, EventArgs e) { // ExampleMethodAsync returns a Task. await ExampleMethodAsync(); textBox1.Text += "\r\nControl returned to Click event handler. public delegate TResult Func<TArg0, TResult>(TArg0 arg0) Func<int, bool> myFunc = x => x == 5; bool result = myFunc(4); // returns false of course var firstNumbersLessThan6 = numbers.TakeWhile(n => n < 6); Référence.
Using a Lambda Expression Over a List in C# This article exemplifies methods for performing several tasks and queries over a set of records in a List.
Sample code is also attached. Sometimes if you have a set of records in a List, it becomes quite easy to query on a list using a Lamda Expression. This article exemplifies methods for performing several tasks and queries over a list. A sample code is also attached with this article to explain the use of Lambda Expressions. Suppose we have a "Person" class that has the following members: class Person{ public string SSN; public string Name; public string Address; public int Age; public Person(string ssn, string name, string addr, int age) { SSN = ssn; Name = name; Address = addr; Age = age; }} Now we create a list of the Person objects in which we have to perform several operations like finding a person on certain conditions, removing a person's record etc.
List<Person> listPersonsInCity = new List<Person>(); ErrorHelp.com - Error Search and Collaboration. Calling an ASP.NET C# Method (Web Method) Using JavaScript. Another title of this article would be "Say bye-bye to Postbacks".
Sometimes we need to stop annoying post-backs on ASP.NET Web Pages. For example, when one click the ASP.NET button on webpage, by default page gets post-back. So, how we stop this by keeping proper code-behind method calls. Let's look at one case. I will create a simple form having two asp.Net textboxes and a button, we will enter our name and address in the textboxes and by clicking button will call the code-behind methods. This is what we are going to create: PageMethod is an easier and faster approach for ASP.NET AJAX. PageMethod is a way through which we can expose the server side page's methods in JavaScript.
Let's create our HTML Page: <div> <p>Say bye-bey to Postbacks. Now, in the above code you can see one instance of the ScriptManager and two textboxes and a button at the end. Note: Remember to add a new attribute EnablePageMethods and set it to true in the ScriptManager. Now, look at the JavaScript Code: