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


C# DoubleVector.LastIndexOf方法代码示例

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


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

示例1: Main


//.........这里部分代码省略.........
      {
        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");
      } catch (ArgumentNullException) {
      }
      {
        // Collection initializer test, requires C# 3.0
//        myDoubleVector = new DoubleVector() { 123.4, 567.8, 901.2 };
      }

      // IndexOf() test
      for (int i=0; i<collectionSize; i++) {
        if (vect.IndexOf(i*10.1) != i)
          throw new Exception("IndexOf test " + i + " failed");
      }
      if (vect.IndexOf(200.1) != -1)
        throw new Exception("IndexOf non-existent test failed");
      if (dv.IndexOf(33.3) != 3)
        throw new Exception("IndexOf position test failed");

      // LastIndexOf() test
      for (int i=0; i<collectionSize; i++) {
        if (vect.LastIndexOf(i*10.1) != i)
          throw new Exception("LastIndexOf test " + i + " failed");
      }
      if (vect.LastIndexOf(200.1) != -1)
        throw new Exception("LastIndexOf non-existent test failed");
      if (dv.LastIndexOf(33.3) != 6)
        throw new Exception("LastIndexOf position test failed");

      // Copy constructor test
      DoubleVector dvCopy = new DoubleVector(dv);
      for (int i=0; i<doubleArray.Length; i++) {
        if (doubleArray[i] != dvCopy[i])
          throw new Exception("Copy constructor failed, index:" + i);
      }
    }
    {
      // Repeat() test
      try {
        myDoubleVector = DoubleVector.Repeat(77.7, -1);
        throw new Exception("Repeat negative count test failed");
      } catch (ArgumentOutOfRangeException) {
      }
      DoubleVector dv = DoubleVector.Repeat(77.7, 5);
      if (dv.Count != 5)
        throw new Exception("Repeat count test failed");
      
      // Also tests enumerator
      {
        System.Collections.IEnumerator myEnumerator = dv.GetEnumerator();
        while ( myEnumerator.MoveNext() ) {
           if ((double)myEnumerator.Current != 77.7)
             throw new Exception("Repeat (1) test failed");
        }
开发者ID:Reticulatas,项目名称:MochaEngineFinal,代码行数:67,代码来源:li_std_vector_runme.cs


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