.4453125using UnityEngine;
using System.Collections;
public class Ex1 : MonoBehaviour {
// Use this for initialization
void Start () {
int t = GetTotal("10", "20", "30", "40", "50", "60", "70");
print (t);
int t2 = GetTotal2("10", "20", "30", "40", "50", "60", "70");
print (t2);
}
int GetTotal (params string[] args){
int total = 0;
for(int i = 0; i < args.Length; i++){
int num = int.Parse(args[i]);
total += num;
}
return total;
}
int GetTotal2 (params string[] args){
int total = 0;
int num = 0;
for(int i = 0; i < args.Length; i++){
if(int.TryParse(args[i], out num)){
total += num;
}
}
return total;
}
// Update is called once per frame
void Update () {
}
}
'Computer Language > 유니티' 카테고리의 다른 글
선택적 매개변수 (기본값이 있을때 매개변수를 생략) (0) | 2014.04.22 |
---|---|
: 을 이용 출력 순서가 바뀌어도 상관이 없다. (0) | 2014.04.22 |
params 가변인자 (0) | 2014.04.22 |
params 매개변수 제한이 없다. (0) | 2014.04.22 |
out 결과값을 받을때 씀 (0) | 2014.04.22 |