"CSharp"의 두 판 사이의 차이

wwiki
이동: 둘러보기, 검색
(새 문서: == 람다식(Lambda Expression) == (매개변수, ...) => 식<syntaxhighlight lang="c#"> class Program { delegate int Calc(int a, int b); public static void Main(string []...)
 
39번째 줄: 39번째 줄:
  
 
== LINQ(Language Integrated Query) ==
 
== LINQ(Language Integrated Query) ==
var value = from ~ in ~
+
var value = from 변수명 in ~
  
 
where ...
 
where ...
  
select value
+
select 변수명;

2020년 8월 16일 (일) 04:42 판

람다식(Lambda Expression)

(매개변수, ...) => 식

class Program
{
    delegate int Calc(int a, int b);
  
    public static void Main(string [] args)
    {
        Calc c = (a, b) => a +b;
        int sum = c(1,1);
    }
}

Func

Func<int> func = () => 10; // 10을 반환
int ten = func();

Func<int, int> square = (x) => x*x;
Cosole.Write(square(10)); // 100출력

Action

Action hello = () => Console.WriteLine("Hello");

hell();
Action<int, int> showSum = (x, y) => 
{
    int sum = x + y;
    Console.Write(sum);
}
showSum(1, 2);

LINQ(Language Integrated Query)

var value = from 변수명 in ~

where ...

select 변수명;