string str = string.Format("{0}{1}","Hello,","World");
// {0}{1}로 두개의 서식 항목을 사용하기 때문에
// "Hello,"와 "World" 두 개의 문자열을 매개변수에 작성
string str = string.Format("{0}{1}{2}",1,":",30);
{0}{1}{2}로 세개의 서식 항목을 사용하기 때문에
1과 ":", 30 세 개의 문자열(정수/실수 가능)을 매개변수에 작성






//string.Format()
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Test : MonoBehaviour
{
int minutes = 1;
int seconds = 30;
private void Update()
{
Debug.Log(string.Format("{0}{1}{2}", minutes, " : ", seconds));
Debug.Log(string.Format("{0, -10:D5}", minutes));
}
}
// 문자열 보간
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Test : MonoBehaviour
{
int minutes = 1;
int seconds = 30;
private void Update()
{
Debug.Log($"{minutes}:{seconds}");
Debug.Log($"{minutes,-10:D5}");
}
}
👆 두 코드 실행시 동일한 결과 값을 출력해낸다