facebook twitter hatena line email

「Unity/Csharp/クラス/Tuple」の版間の差分

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
(ページの作成:「==Tupleとは== 戻り値を2つにできるもの ==Tupleサンプル== <pre> using System; class Program { // 名前付き Tuple を返す static (int age,...」)
 
(Tupleとは)
 
(同じ利用者による、間の1版が非表示)
行1: 行1:
 
==Tupleとは==
 
==Tupleとは==
 
戻り値を2つにできるもの
 
戻り値を2つにできるもの
 +
 +
(int age, string name)のようにいれるのはc#7.0から
  
 
==Tupleサンプル==
 
==Tupleサンプル==
行21: 行23:
 
</pre>
 
</pre>
  
==個別の==
+
==個別の変数に直接いれる場合==
 
<pre>
 
<pre>
 
using System;
 
using System;

2025年1月31日 (金) 14:14時点における最新版

Tupleとは

戻り値を2つにできるもの

(int age, string name)のようにいれるのはc#7.0から

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}");
    }
}