Câu hỏi phỏng vấn C#
Câu hỏi

What is the difference bet...

Câu trả lời

Here is the difference between Lambdas and Delegates in C#:

Lambdas

  • Lambdas are anonymous functions that can be passed as arguments to methods or assigned to variables.
  • They are defined using the => operator, which separates the lambda's parameters from its body.
  • Lambdas can capture variables from their enclosing scope, allowing them to access and modify variables outside of their own body.
  • Lambdas are often used with LINQ queries and methods like Where, Select, OrderBy, etc.
  • Example:
    csharp Copy
    Func<int, int> square = x => x * x;
    int result = square(5); // result = 25

Delegates

  • Delegates are types that represent methods with a particular signature (return type and parameter types).
  • They are declared with a method signature and can be assigned to variables or p...
expert

expert

Gợi ý câu hỏi phỏng vấn

junior

What is Boxing and Unboxing?

senior

What is the difference between System.ApplicationException class and System.SystemException class?

junior

What are Nullable types in C#?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào