如何使用Tuple实现此代码?

时间:2019-05-20 08:37:20

标签: c# tuples

class Program
{
    public static void Print(MethodArguments args)
    {
        Console.WriteLine("ID = " + args.ID.ToString());
        Console.WriteLine("Name =  " + args.Name);
    }
    public static void Main(string[] args)
    {
        MethodArguments arguments = new MethodArguments();
        arguments.ID = 20;
        arguments.Name = "John";
        Print(arguments);
        Console.ReadKey();
    }
}

1 个答案:

答案 0 :(得分:0)

class Program
{
    private static void Print((int Id, string Name) args)
    {
        Console.WriteLine($"ID = {args.Id.ToString()}");
        Console.WriteLine($"Name = {args.Name}");
    }
    public static void Main(string[] args)
    {
        Print((20, "John"));
        Console.ReadKey();
    }
}