'전체 글'에 해당되는 글 1801건

  1. 2019.04.05 (C#) Array to Dictionary (Linq)
  2. 2019.04.03 (java) Jackson
  3. 2019.04.03 (java) File (상대경로)
  4. 2019.04.02 Hash Tables and Hash Functions
  5. 2019.04.02 [pdf] Cg-3.1_April2012_ReferenceManual
  6. 2019.04.02 [pdf] CgUsersManual

(C#) Array to Dictionary (Linq)

Unity3D/C# 2019. 4. 5. 13:52
반응형

T[]에는 ToDictionary에 대한 정의가 포함되어 있지 않고 가장적합한 확장 메서드 오버로드 Enumerable.ToDictionary<int, T>(IEnumerable, Func<int, T> 에는 IEnumerable형식의 수신기가 필요합니다.

 

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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace ConsoleApp1
{
    public class App
    {
        private DataLoader dataLoader;      //데이터 로드 담당 
        private DataStorage dataStorage;    //데이터 자장 담당 
 
        public App()
        {
            this.dataLoader = new DataLoader();
            this.dataStorage = new DataStorage();
        }
 
        public void Start()
        {
            this.DisplayDataValues<WeaponData>("./data/weapon_data.json");
            Console.WriteLine();
            this.DisplayDataValues<CharacterData>("./data/character_data.json");
        }
 
        public void DisplayDataValues<T>(string path) where T : RawData
        {
            //데이터 로드 (파일 읽기)
            var arrWeaponDatas = this.dataLoader.LoadData<T>(path);
            this.dataStorage.Store<T>(arrWeaponDatas);
            //불러오기 테스트 
            T[] values = dataStorage.GetData<T>();
            Dictionary<int, T> dictionary = values.ToDictionary(data => data.id);
 
            //T[]에는 ToDictionary에 대한 정의가 포함되어 있지 않고 가장적합한 확장 메서드 오버로드 Enumerable.ToDictionary<int, T>(IEnumerable, Func<int, T> 에는 IEnumerable형식의 수신기가 필요합니다.
            //var dictionary = values.ToDictionary<int, T>(data => data.id);
 
 
            // Display all keys and values.
            foreach (KeyValuePair<int, T> pair in dictionary)
            {
                Console.WriteLine("{0}"pair.Value.id);
            }
        }
    }
}
 
 
 

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var app = new App();
            app.Start();
 
            //var test = new Test();
            //test.Test3();
        }
    }
}
 
 
 

 

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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
 
namespace ConsoleApp1
{
    //데이터 로드 클래스 
    public class DataLoader
    {
        public DataLoader()
        {
 
        }
 
        //데이터 로드 메서드 
        public T[] LoadData<T>(string path)
        {
            //파일 읽기 
            var json = File.ReadAllText(path);
            //역직렬화 
            var arrDatas = JsonConvert.DeserializeObject<T[]>(json);
            return arrDatas;
        }
    }
}
 
 
 

 

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
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Linq;
 
namespace ConsoleApp1
{
    //데이터 적재 클래스 
    public class DataStorage
    {
        private ArrayList arrayList;
 
        public DataStorage()
        {
            this.arrayList = new ArrayList();
        }
 
        //저장 
        public void Store<T>(T[] arrDatas) where T : RawData
        {
            arrayList.Add(arrDatas);
        }
 
        //불러오기 
        public T[] GetData<T>()
        {
            T[] rtnArrDatas = null;
 
            foreach (var arr in this.arrayList)
            {
                if (arr is T[])
                {
                    rtnArrDatas = arr as T[];
                    break;
                }
            }
            return rtnArrDatas;
        }
    }
}
 
 
 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace ConsoleApp1
{
    //데이터 매핑 클래스 (바인딩클래스)
    public class WeaponData : RawData
    {
        public string name;
        public int max_level;
        public float damage_min;
        public float damage_max;
    }
}
 
 
 

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace ConsoleApp1
{
    public class RawData
    {
        public int id;
    }
}
 
 
 

 

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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace ConsoleApp1
{
    public class Test
    {
        public Test()
        {
        }
 
        public void Test1()
        {
            // Example integer array.
            int[] values = new int[]
            {
            1,
            3,
            5,
            7
            };
 
            // First argument is the key, second the value.
            Dictionary<intbool> dictionary =
                values.ToDictionary(v => v, v => true);
 
            // Display all keys and values.
            foreach (KeyValuePair<intbool> pair in dictionary)
            {
                Console.WriteLine(pair);
            }
        }
 
        public void Test2()
        {
            // Example integer array.
            WeaponData[] values = new WeaponData[] { };
 
            // First argument is the key, second the value.
            Dictionary<int, WeaponData> dictionary =
                values.ToDictionary(data => data.id);
 
            // Display all keys and values.
            foreach (KeyValuePair<int, WeaponData> pair in dictionary)
            {
                Console.WriteLine(pair);
            }
        }
 
        public void Test3()
        {
            var dataLoader = new DataLoader();
            var dataStorage = new DataStorage();
 
 
 
            //데이터 로드 (파일 읽기)
            var arrWeaponDatas = dataLoader.LoadData<WeaponData>("./data/weapon_data.json");
            dataStorage.Store<WeaponData>(arrWeaponDatas);
 
            // Example integer array.
            WeaponData[] values = dataStorage.GetData<WeaponData>();
 
            // First argument is the key, second the value.
            Dictionary<int, WeaponData> dictionary =
                values.ToDictionary(data => data.id);
 
            // Display all keys and values.
            foreach (KeyValuePair<int, WeaponData> pair in dictionary)
            {
                Console.WriteLine("{0} {1}"pair.Value.id, pair.Value.name);
            }
        }
    }
}
 
 
 
반응형

'Unity3D > C#' 카테고리의 다른 글

(C#) resolving-method-overloads  (0) 2019.04.10
(C#) 타입 비교  (0) 2019.04.05
인벤토리 만들기 (제너릭)  (0) 2019.04.02
referencesource microsoft  (0) 2019.04.02
IEnumerator, IEnumerable 상속받은 Inventory 구현 (인덱서)  (0) 2019.04.01
:

(java) Jackson

ETC 2019. 4. 3. 21:49
반응형

https://www.journaldev.com/2324/jackson-json-java-parser-api-example-tutorial#jackson-json-example

 

Jackson JSON Java Parser API Example Tutorial - JournalDev

Jackson JSON Java API for parsing JSON data example tutorial, ObjectMapper, JSON to POJO, JSON to Java Object, Java Object to JSON

www.journaldev.com

json파일 읽어서 맵에 추가 하기 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
package chap01;
 
 
public class Hello {
 
    public static void main(String args[]) throws IOException {
        System.out.println("Hello World!");
        
        App app = new App();
        app.Start();
    }
}
 
 
 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
package chap01;
 
public class ItemData 
{    
    public int id;
    public String name;
    public int max_level;
    public float damage_min;
    public float damage_max;
    
    public ItemData()
    {
        
    }
}
 
 

 

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
package chap01;
 
 
 
public class App {
    
    private Map<Integer, ItemData> mapItemData;
    
    public App()
    {
        this.mapItemData = new HashMap<Integer, ItemData>();    
    }
    
    public void Start() throws IOException
    {
 
        ObjectMapper mapper = new ObjectMapper();
        String path = "D:\\workspace\\java\\chap01\\bin\\weapon_data.json";
        byte[] jsonData = Files.readAllBytes(Paths.get(path));
        System.out.println(jsonData.length);
        ItemData[] arrItemData = mapper.readValue(jsonData, ItemData[].class);
        System.out.println(arrItemData.length);
        for(int i = 0; i<arrItemData.length; i++)
        {
            ItemData data = arrItemData[i];
            this.mapItemData.put(data.id, data);
        }
        
        ItemData data = this.mapItemData.get(0);
        System.out.println(String.format("%s, %s, %s, %s"data.id, data.name, data.damage_min, data.damage_max));
    }
}
 
 
 

 

 

반응형

'ETC' 카테고리의 다른 글

별찍기  (0) 2019.09.19
웹 개발자가 되는 방법 - 웹 개발 로드맵  (0) 2019.08.07
(java) File (상대경로)  (0) 2019.04.03
이것이 자바다 - 1.1 프로그래밍 언어란?  (0) 2019.03.29
Jenkins 젠킨스 + Unity 빌드  (0) 2019.02.08
:

(java) File (상대경로)

ETC 2019. 4. 3. 21:18
반응형

https://okky.kr/article/271934

 

OKKY | getClass().getResourceAsStream() 사용시 경로설정

웹플젝에서 src/main/java/com/test/util에 있는 utilTest.java에서 src/main/resource에 있는 testImage.png를 가져오고 싶어서.. getClass().getResourceAsStream("/main/resource/testImage.png"); 하니 null나오는군요..; 경로 저

okky.kr

반응형
:

Hash Tables and Hash Functions

Algorithm 2019. 4. 2. 23:24
반응형

https://referencesource.microsoft.com/#mscorlib/system/collections/hashtable.cs,10fefb6e0ae510dd

 

Reference Source

 

referencesource.microsoft.com

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
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace ConsoleApp10
{
    class Program
    {
        static void Main(string[] args)
        {
            // TODO: 여기에 응용 프로그램을 시작하는 코드를 추가합니다.
            string str = "홍길동";
            char[] charArray = str.ToCharArray();
            Console.WriteLine("Char Array");
            //        for(int i=0;i<charArray.Length;i++) 
            //                Console.WriteLine((int)charArray[i]); 
            foreach (char a in charArray)
                Console.WriteLine("{0}", (int)a);
 
            Console.WriteLine();
 
            byte[] byteArray = System.Text.ASCIIEncoding.Default.GetBytes(str);
 
            Console.WriteLine("Byte Array");
            //        for(int i=0;i<byteArray.Length;i++) 
            //                Console.WriteLine(byteArray[i]); 
            int sum = 0;
            foreach (char a in byteArray) {
                sum += (int)a;
                Console.WriteLine("{0}", (int)a);
            }
 
            Console.WriteLine("sum: {0}", sum % 11);
                
        }
    }
}
 
 
 

 

반응형

'Algorithm' 카테고리의 다른 글

[백준] 11047 동전 0 (진행중)  (0) 2019.08.13
[백준] ATM 11399  (0) 2019.08.12
설탕 배달  (0) 2019.06.11
그래프  (0) 2019.06.11
A* Pathfinding for Beginner By Patrick Lester  (0) 2019.05.22
:

[pdf] Cg-3.1_April2012_ReferenceManual

Graphics Programming 2019. 4. 2. 19:57
반응형

http://developer.download.nvidia.com/cg/Cg_3.1/Cg-3.1_April2012_ReferenceManual.pdf

반응형

'Graphics Programming' 카테고리의 다른 글

셰이더 시맨틱  (0) 2019.04.27
Shader - Always Visible - [Tutorial][C#]  (0) 2019.04.25
[pdf] CgUsersManual  (0) 2019.04.02
Unity Shader Study Day-01  (0) 2019.03.31
:

[pdf] CgUsersManual

Graphics Programming 2019. 4. 2. 19:54
반응형

http://developer.download.nvidia.com/cg/Cg_3.0/CgUsersManual.pdf

반응형

'Graphics Programming' 카테고리의 다른 글

셰이더 시맨틱  (0) 2019.04.27
Shader - Always Visible - [Tutorial][C#]  (0) 2019.04.25
[pdf] Cg-3.1_April2012_ReferenceManual  (0) 2019.04.02
Unity Shader Study Day-01  (0) 2019.03.31
: