C# 기술
[C#] Tuple 사용하기
bryan.oh
2021. 10. 20. 23:36
반응형
1. 함수의 return type 에 괄호로 리턴 형식과 이름을 지정합니다.
2. return 할때 그 형식에 맞게 괄호 안에 값을 넣어서 리턴합니다.
private (bool isValid, string hh, string mm) getControlValues()
{
if (comboBox_hh.SelectedItem == null || comboBox_mm.SelectedItem == null)
{
MessageBox.Show("Time is required.");
return (false, "", "");
}
string hh = comboBox_hh.SelectedItem.ToString();
string mm = comboBox_mm.SelectedItem.ToString();
return (true, hh, mm);
}
3. 호출하는 곳에서 사용하려면,
var tuple = getControlValues();
if( tuple.isValid ){
Console.WriteLine(tuple.hh);
Console.WriteLine(tuple.mm);
}
728x90
반응형