dnrkckzk 초보 유니티 개발자 개발하면서 겪는 어려움들을 해결했을 때, 인터넷 돌아다니는 흥미 있는 글 있을 때, 저장하고 공유하기 위한 공간.

카테고리

전체보기 (42)
뇌를 자극하는 C# 5.0프로그래밍 (9)
Unity Tip (30)
C# (1)
Total
Today
Yesterday

1.다음 코드의 출력 결과값은 얼마일까요?


1
2
3
4
5
6
7
8
9
10
11
12
13
namespace Ex14_1
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            Func<int> func_1 = () => 10;
            Func<intint> func_2 = (a) => a * 2;
 
            Console.WriteLine(func_1() + func_2(30));
        }
    }
}
cs


실행해보면 70이 나온당.


70!



===========================================================================================================]


2.다음 코드에서 익명 메소드를 람다식으로 수정하세요.



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
namespace Ex14_2
{
    class MainApp
    {    
        static void Main(string[] args)
        {
            int[] array = { 1122334455 };
 
            foreach (int a in array)
            {
                Action action = new Action                
                (                    
                     delegate()
                    {
                        Console.WriteLine(a * a);
                
                    }
                );
                action.Invoke();
            }
        }
    }
}
cs


이 코드를 !


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
namespace Ex14_2
{
    class MainApp
    {    
        static void Main(string[] args)
        {
            int[] array = { 1122334455 };
 
            foreach (int a in array)
            {            
                Action action = () => Console.WriteLine(a * a);
                action.Invoke();
            }
        }
    }
}
cs




이렇게 바꾸는게 가장 깔끔한 것 같다.



Posted by dnrkckzk
, |

최근에 달린 댓글

최근에 받은 트랙백

글 보관함