일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 백준
- Java
- C#강의
- 누적합
- popleft
- 소수찾기
- 1일1솔
- 완전탐색
- 소수판별
- 브루투포스
- unity
- python3
- spring
- 연관관계
- 프로그래머스
- 파이썬
- 그리디 알고리즘
- 우선순위큐
- mvc
- c#
- BFS
- deque
- appendleft
- 합 구하기
- DP
- pypy3
- 인프런
- JPA
- LCM
- Python
Archives
- Today
- Total
jae_coding
[유니티로 배우는 C#] 배열 본문
반응형
변수들의 집합체: 배열
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Unity_lecture : MonoBehaviour
{
// 배열의 선언
int [] exp = {50, 100, 150, 200, 250, 300};
void Start(){
// case 1
print(exp[1]); // 여서 1은 index (배열의 Index는 0부터 시작하므로 100이 출력)
print(exp[2]); // 150출력
print(exp[3]); // 200출력
print(exp[4]); // 250출력
print(exp[5]); // 300출력
print(exp[6]); // index의 범위가 0~5이기 때문에 out of range라는 오류가 발생
// case 2
for (int i = 1; i <= 5; i++){
print(exp[i]);
}
// case 3
for (int i = 1; i <= exp.Length-1; i++){
print(exp[i]);
}
// case1과 case2, 그리고 case3는 동일한 결과를 나타내는 코드
}
}
배열의 요소 추가하기
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Unity_lecture : MonoBehaviour
{
// 배열의 크기를 지정
int[] array = new int[10];
void Start(){
for (int i = 0; i < array.Length; i++){
array[i] = i * 50;
print(array[i]);
}
}
}
2차원 배열
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Unity_lecture : MonoBehaviour
{
// 2차원 배열 선언하기
int[,] array2 = {{1, 2, 3, 4, 5}, {10, 20, 30, 40, 50}};
void Start(){
print(array2[1, 3]); // 40 출력
print(array2[0, 1]); // 2 출력
}
}
배열의 크기는 변경할 수 없으니 처음에 선언할 때 잘 선언해야하는 것이 중요하다!
강의자료: 케이디 유튜브
반응형
'C#' 카테고리의 다른 글
[유니티로 배우는 C#] 네임스페이스 (0) | 2022.07.19 |
---|---|
[유니티로 배우는 C#] 컬렉션 (0) | 2022.07.19 |
[유니티로 배우는 C#] 접근 지정자 & 범위 지정자 (0) | 2022.07.19 |
[유니티로 배우는 C#] 함수 (0) | 2022.07.19 |
[유니티로 배우는 C#] 자료형 (0) | 2022.07.19 |
Comments