← Back to C# Course | Chapter 12: Delegates & Events | Lesson 3 of 6

Lambda Expressions क्या हैं

एक lambda एक छोटा नामहीन function है जो तुरंत लिखा जाता है, जैसे instructions की एक quick sticky note। यह किसी list को filter करने जैसे छोटे कामों के लिए सुविधाजनक है।

In this page:

  1. Lambda Expressions
Syntax
csharp
(parameters) => expression
(parameters) => { statements; return value; }

DelegateName variable = x => x * 2;

Lambda Expressions

एक lambda expression => syntax उपयोग करते हुए एक compact, inline, नामहीन function है, जहां भी एक delegate की उम्मीद हो वहां उपयोगी। (x, y) => x + y एक पूरे method के बराबर है लेकिन inline लिखा गया।

Lambdas LINQ, event handlers, और Func/Action के साथ भारी उपयोग होते हैं।

Note: single expression body वाले lambda को कोई return या braces नहीं चाहिए — expression की value अपने आप return होती है।

उदाहरण: Lambda Expressions

markup
using System;

delegate int Transform(int x);

class Program
{
    static void Main(string[] args)
    {
        Transform square = x => x * x;
        Transform increment = x => x + 1;

        Console.WriteLine(square(5));
        Console.WriteLine(increment(5));
    }
}
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. किसी lambda में एक loop variable capture करना और बाद में इसकी value से हैरान होना।
  2. delegate type के लिए गलत parameters वाला एक lambda लिखना, जो एक compile error है।
  3. किसी lambda को लंबा और जटिल बनाना, जब एक named method ज़्यादा साफ़ होता।
🔒

Chapter Quiz — Complete all 6 topics to unlock

0/6 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.