当前位置: 首页>>代码示例>>C#>>正文


C# Tuple<T1,T2,T3,T4,T5,T6,T7>类代码示例

本文整理汇总了C#中System.Tuple<T1,T2,T3,T4,T5,T6,T7>的典型用法代码示例。如果您正苦于以下问题:C# Tuple<T1,T2,T3,T4,T5,T6,T7>类的具体用法?C# Tuple<T1,T2,T3,T4,T5,T6,T7>怎么用?C# Tuple<T1,T2,T3,T4,T5,T6,T7>使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Tuple<T1,T2,T3,T4,T5,T6,T7>类属于System命名空间,在下文中一共展示了Tuple<T1,T2,T3,T4,T5,T6,T7>类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

//引入命名空间
using System;

public class Example
{
   public static void Main()
   {
      // Get population data for New York City, 1950-2000.
      var population = Tuple.Create("New York", 7891957, 7781984, 
                                    7894862, 7071639, 7322564, 8008278);
      var rate = ComputePopulationChange(population);
      // Display results.
      Console.WriteLine("Population Change, {0}, 1950-2000\n", population.Item1);
      Console.WriteLine("Year      {0,10} {1,9}", "Population", "Annual Rate");
      Console.WriteLine("1950      {0,10:N0} {1,11}", population.Item2, "NA");
      Console.WriteLine("1960      {0,10:N0} {1,11:P2}", population.Item3, rate.Item2/10);
      Console.WriteLine("1970      {0,10:N0} {1,11:P2}", population.Item4, rate.Item3/10);
      Console.WriteLine("1980      {0,10:N0} {1,11:P2}", population.Item5, rate.Item4/10);
      Console.WriteLine("1990      {0,10:N0} {1,11:P2}", population.Item6, rate.Item5/10);
      Console.WriteLine("2000      {0,10:N0} {1,11:P2}", population.Item7, rate.Item6/10);
      Console.WriteLine("1950-2000 {0,10:N0} {1,11:P2}", "", rate.Item7/50);
   }

   private static Tuple<string, double, double, double, double, double, double> 
        ComputePopulationChange(
           Tuple<string, int, int, int, int, int, int> data)  
   {           
      var rate = Tuple.Create(data.Item1, 
                       (double)(data.Item3 - data.Item2)/data.Item2, 
                       (double)(data.Item4 - data.Item3)/data.Item3, 
                       (double)(data.Item5 - data.Item4)/data.Item4, 
                       (double)(data.Item6 - data.Item5)/data.Item5,
                       (double)(data.Item7 - data.Item6)/data.Item6,
                       (double)(data.Item7 - data.Item2)/data.Item2 );
      return rate;
   }           
}
开发者ID:.NET开发者,项目名称:System,代码行数:37,代码来源:Tuple

输出:

Population Change, New York, 1950-2000

Year      Population Annual Rate
1950       7,891,957          NA
1960       7,781,984     -0.14 %
1970       7,894,862      0.15 %
1980       7,071,639     -1.04 %
1990       7,322,564      0.35 %
2000       8,008,278      0.94 %
1950-2000                 0.03 %


注:本文中的System.Tuple<T1,T2,T3,T4,T5,T6,T7>类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。