우노[UNO] COLLECTIONS 알아보기

퓨즈[Fusetools]의 컬렉션 타입들에 대한 코드 샘플인데요. 일반적인 언어에 있는 자료구조들과 사용법이 유사합니다.

https://www.fusetools.com/docs/uno/collections

우노 기본 프로젝트는 아래 페이지에서 다운로드 받으실 수 있습니다.
우노[UNO] 학습을 위한 기본 프로젝트 바로가기

[[ UnoPlayground.uno ]]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
using Fuse.Scripting;
using Uno.Collections;

public class UnoPlayground : NativeModule
{
    public UnoPlayground()
    {
        AddMember(new NativeFunction("testDictionary", (NativeCallback)testDictionary));
        AddMember(new NativeFunction("testHashSet", (NativeCallback)testHashSet));
        AddMember(new NativeFunction("testLinkedList", (NativeCallback)testLinkedList));
        AddMember(new NativeFunction("testList", (NativeCallback)testList));
        AddMember(new NativeFunction("testQueue", (NativeCallback)testQueue));
        AddMember(new NativeFunction("testStack", (NativeCallback)testStack));
    }

    static object[] testDictionary(Context c, object[] args)
    {
        debug_log("testDictionary ::");

        Dictionary<string, string> dic = new Dictionary<string, string>();
        dic.Add("name", "Kangmin Won");
        dic.Add("blog", "http://blog.wonhada.com");
        debug_log("Count: " + dic.Count);// 2
        debug_log("Blog: " + dic["blog"]);// http://blog.wonhada.com

        return null;
    }

    static object[] testHashSet(Context c, object[] args)
    {
        debug_log("testHashSet ::");

        HashSet<string> hashSet = new HashSet<string>();
        hashSet.Add("Kangmin Won");
        hashSet.Add("Kangmin Won");// Set이므로 추가되지 않는다.
        hashSet.Add("http://blog.wonhada.com");
        debug_log("Count: " + hashSet.Count);// 2
        debug_log("Contains wonHada: " + hashSet.Contains("wonHada"));// False
        debug_log("Contains Kangmin Won: " + hashSet.Contains("Kangmin Won"));// True

        return null;
    }

    static object[] testLinkedList(Context c, object[] args)
    {
        debug_log("testLinkedList ::");

        LinkedList<string> linkedList = new LinkedList<string>();
        linkedList.AddLast("Kangmin");
        linkedList.AddLast("Won");
        linkedList.AddLast("http://blog.wonhada.com");

        LinkedListNode<string> node = linkedList.First;
        while(node != null)
        {
            debug_log(node.Value);// (1)Kangmin, (2)Won, (3)http://blog.wonhada.com
            node = node.Next;
        }

        return null;
    }

    static object[] testList(Context c, object[] args)
    {
        debug_log("testList ::");

        List<string> list = new List<string>();
        list.Add("Kangmin");
        list.Add("http://blog.wonhada.com");
        list.Insert(1, "Won");

        for(int i = 0; i < list.Count; ++i)
        {
            debug_log(list[i]);// (1)Kangmin, (2)Won, (3)http://blog.wonhada.com
        }

        return null;
    }

    static object[] testQueue(Context c, object[] args)
    {
        debug_log("testQueue ::");

        Queue<string> queue = new Queue<string>();
        queue.Enqueue("Kangmin");
        queue.Enqueue("Won");
        queue.Enqueue("http://blog.wonhada.com");

        debug_log("Count: " + queue.Count);// 3
       
        for(int i = queue.Count - 1; i >= 0; --i)
        {
            debug_log(queue.Dequeue());// (1)Kangmin, (2)Won, (3)http://blog.wonhada.com
        }

        debug_log("Count: " + queue.Count);// 0

        return null;
    }

    static object[] testStack(Context c, object[] args)
    {
        debug_log("testStack ::");

        Stack<string> stack = new Stack<string>();
        stack.Push("http://blog.wonhada.com");
        stack.Push("Won");
        stack.Push("Kangmin");

        debug_log("Count: " + stack.Count);// 3
       
        for(int i = stack.Count - 1; i >= 0; --i)
        {
            debug_log(stack.Pop());// (1)Kangmin, (2)Won, (3)http://blog.wonhada.com
        }

        debug_log("Count: " + stack.Count);// 0

        return null;
    }
}

[[ MainView.ux ]]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<App>
    <UnoPlayground ux:Global="UnoPlayground" />

    <StackPanel>
        <JavaScript>
            var UnoPlayground = require("UnoPlayground");
            UnoPlayground.testDictionary();
            // UnoPlayground.testHashSet();
            // UnoPlayground.testLinkedList();
            // UnoPlayground.testList();
            // UnoPlayground.testQueue();
            // UnoPlayground.testStack();
        </JavaScript>
    </StackPanel>
</App>

[[ 동영상 강좌(재생 목록 버튼을 누르세요) ]]

Was this article helpful?

Related Articles