Unity/Csharp/クラス/Tuple
Tupleとは
戻り値を2つにできるもの
Tupleサンプル
using System;
class Program
{
// 名前付き Tuple を返す
static (int age, string name) GetPersonData()
{
return (25, "Taro");
}
static void Main()
{
var person = GetPersonData();
Console.WriteLine($"年齢: {person.age}, 名前: {person.name}");
}
}
個別の
using System;
class Program
{
static (int age, string name) GetPersonData()
{
return (25, "Taro");
}
static void Main()
{
var (age, name) = GetPersonData();
Console.WriteLine($"年齢: {age}, 名前: {name}");
}
}