using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace learn_hide_function
{
    internal class Program
    {
        
        static void Main(string[] args)
        {
            int a = 123;
            string b = "zzz";
            // FuncTuple是静态方法可以直接调用
            (int t, string y) = FuncTuple(a, b);
            // 由于Main的类型是static,所以使用类方法前需要实例化一下
            Program program = new Program();
            program.TestFunc();

            // 声明和使用元组
            // 第一种声明和使用方法
            (int, string) jjj = (123, "jkl");
            Console.WriteLine($"jjj is {jjj.Item1} + {jjj.Item2}");

            // 第一种声明方法
            (int age, string name) kkk = (123, "jkl");
            Console.WriteLine($"kkk is {kkk.age} + {kkk.name}");

            Console.ReadKey();

        }
        // 静态方法返回元组
        static (int , string) FuncTuple(int aaa, string bbb)
        {
            aaa += aaa;
            bbb += "aaa";
            // 使用元组一次返回多个值
            return (aaa, bbb);
        }
        // 类方法返回元组
        public (int, string) FuncTuple2(int aaa, string bbb)
        {
            aaa += aaa;
            bbb += "aaa";
            return (aaa, bbb);
        }
        // 写个类方法,测试类方法可以直接调用类方法
        public void TestFunc()
        {
            int a = 123;
            string b = "zzz";
            // TestFunc是类方法,可以直接调用类方法和静态方法
            (int t, string y) = FuncTuple(a, b);
            // 快速定义一个元组
            var(i, o) = FuncTuple2(a, b);
            Console.WriteLine($"t {t} y {y} i {i} o {o}");
        }
    }
}

输出结果

t 246 y zzzaaa i 246 o zzzaaa
jjj is 123 + jkl
kkk is 123 + jkl
posted on 2023-01-20 21:15  盈盈的月儿  阅读(18)  评论(0编辑  收藏  举报