zoukankan      html  css  js  c++  java
  • 元组简单示例

    元组简单示例

    数组合并了相同类型的对象,而元组合并了不同类型的对象。

    泛型元组的使用

    public static Tuple<int, int> Divide(int dividend, int divisor)
    {
        int result = dividend / divisor;
        int reminder = dividend % divisor;
        return Tuple.Create<int, int>(result, reminder);
    }
    
    
    //调用
    var result = Divide(5, 2);
    Console.WriteLine("result of divison:{0},reminder:{1}",result.Item1,result.Item2);
    

    超过8个元组的使用方法

    由于最后一个模板参数是TResult,表示必须给它传递一个元组。这样就可以创建带任意个参数的元组了。

    //定义方法如下
    Tuple<int, int, int, int, int, int,int,Tuple<Tuple<bool, bool>>> tup = Tuple.Create<int, int, int, int, int, int, int, Tuple<bool, bool>>(1, 2, 3, 4, 5, 6, 7, Tuple.Create<bool, bool>(true, true));
    
    
    var tup2 = Tuple.Create<int, int, int, int, int, int, int, Tuple<bool, bool>>(1, 2, 3, 4, 5, 6, 7, Tuple.Create<bool, bool>(true, true));
    
    //定义方法的写法
    public static Tuple<int, int, int, int, int, int, int, Tuple<Tuple<bool, bool>>> DividePlus(int i1, int i2, int i3, int i4, int i5, int i6, int i7, Tuple<bool, bool> result)
    {
    return Tuple.Create<int, int, int, int, int, int, int, Tuple<bool, bool>>(i1, i2, i3, i4, i5, i6, i7, Tuple.Create<bool, bool>(result.Item1, result.Item2));
    }
    
  • 相关阅读:
    Nginx负载均衡+代理+ssl+压力测试
    Nginx配置文件详解
    HDU ACM 1690 Bus System (SPFA)
    HDU ACM 1224 Free DIY Tour (SPFA)
    HDU ACM 1869 六度分离(Floyd)
    HDU ACM 2066 一个人的旅行
    HDU ACM 3790 最短路径问题
    HDU ACM 1879 继续畅通工程
    HDU ACM 1856 More is better(并查集)
    HDU ACM 1325 / POJ 1308 Is It A Tree?
  • 原文地址:https://www.cnblogs.com/liuguangyin/p/6917779.html
Copyright © 2011-2022 走看看