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


C# DoubleVector.Contains方法代码示例

本文整理汇总了C#中DoubleVector.Contains方法的典型用法代码示例。如果您正苦于以下问题:C# DoubleVector.Contains方法的具体用法?C# DoubleVector.Contains怎么用?C# DoubleVector.Contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DoubleVector的用法示例。


在下文中一共展示了DoubleVector.Contains方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main


//.........这里部分代码省略.........
        throw new Exception("CopyTo (4) test failed");
      } catch (ArgumentException) {
      }
    }
    {
      StructVector inputvector = new StructVector();
      int arrayLen = 10;
      for (int i=0; i<arrayLen; i++) {
        inputvector.Add(new Struct(i/10.0));
      }
      Struct[] outputarray = new Struct[arrayLen];
      inputvector.CopyTo(outputarray);
      for(int i=0; i<arrayLen; i++) {
        if (outputarray[i].num != inputvector[i].num)
          throw new Exception("CopyTo (6) test failed, i:" + i);
      }
      foreach (Struct s in inputvector) {
        s.num += 20.0;
      }
      for(int i=0; i<arrayLen; i++) {
        if (outputarray[i].num + 20.0 != inputvector[i].num )
          throw new Exception("CopyTo (7) test failed (only a shallow copy was made), i:" + i);
      }
    }
    {
      try {
        vect.CopyTo(null);
        throw new Exception("CopyTo (8) test failed");
      } catch (ArgumentNullException) {
      }
    }

    // Contains() test
    if (!vect.Contains(0*10.1))
      throw new Exception("Contains test 1 failed");
    if (!vect.Contains(10*10.1))
      throw new Exception("Contains test 2 failed");
    if (!vect.Contains(19*10.1))
      throw new Exception("Contains test 3 failed");
    if (vect.Contains(20*10.1))
      throw new Exception("Contains test 4 failed");

    {
      // ICollection constructor
      double[] doubleArray = new double[] { 0.0, 11.1, 22.2, 33.3, 44.4, 55.5, 33.3 };
      DoubleVector dv = new DoubleVector(doubleArray);
      if (doubleArray.Length != dv.Count)
        throw new Exception("ICollection constructor length check failed: " + doubleArray.Length + "-" + dv.Count);
      for (int i=0; i<doubleArray.Length; i++) {
        if (doubleArray[i] != dv[i])
          throw new Exception("ICollection constructor failed, index:" + i);
      }
      {
        Struct[] structArray = new Struct[] { new Struct(0.0), new Struct(11.1), new Struct(22.2), new Struct(33.3) };
        StructVector sv = new StructVector(structArray);
        for (int i=0; i<structArray.Length; i++) {
          structArray[i].num += 200.0;
        }
        for (int i=0; i<structArray.Length; i++) {
          if (structArray[i].num != sv[i].num + 200.0)
            throw new Exception("ICollection constructor not a deep copy, index:" + i);
        }
      }
      try {
        new DoubleVector((System.Collections.ICollection)null);
        throw new Exception("ICollection constructor null test failed");
开发者ID:Reticulatas,项目名称:MochaEngineFinal,代码行数:67,代码来源:li_std_vector_runme.cs


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