알 수 없는 사용자 2014. 4. 22. 14:27

.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 () {

}

}