本文整理汇总了C#中DoubleVector.CopyTo方法的典型用法代码示例。如果您正苦于以下问题:C# DoubleVector.CopyTo方法的具体用法?C# DoubleVector.CopyTo怎么用?C# DoubleVector.CopyTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DoubleVector
的用法示例。
在下文中一共展示了DoubleVector.CopyTo方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
public static void Main() {
// Setup collection
DoubleVector vect = new DoubleVector();
for (int i=0; i<collectionSize; i++) {
double num = i*10.1;
vect.Add(num);
}
// Count property test
if (vect.Count != collectionSize)
throw new Exception("Count test failed");
// IsFixedSize property test
if (vect.IsFixedSize)
throw new Exception("IsFixedSize test failed");
// IsReadOnly property test
if (vect.IsReadOnly)
throw new Exception("IsReadOnly test failed");
// Item indexing
vect[0] = 200.1;
if (vect[0] != 200.1)
throw new Exception("Item property test failed");
vect[0] = 0*10.1;
try {
vect[-1] = 777.1;
throw new Exception("Item out of range (1) test failed");
} catch (ArgumentOutOfRangeException) {
}
try {
vect[vect.Count] = 777.1;
throw new Exception("Item out of range (2) test failed");
} catch (ArgumentOutOfRangeException) {
}
// CopyTo() test
{
double[] outputarray = new double[collectionSize];
vect.CopyTo(outputarray);
int index = 0;
foreach(double val in outputarray) {
if (vect[index] != val)
throw new Exception("CopyTo (1) test failed, index:" + index);
index++;
}
}
{
double[] outputarray = new double[midCollection+collectionSize];
vect.CopyTo(outputarray, midCollection);
int index = midCollection;
foreach(double val in vect) {
if (outputarray[index] != val)
throw new Exception("CopyTo (2) test failed, index:" + index);
index++;
}
}
{
double[] outputarray = new double[3];
vect.CopyTo(10, outputarray, 1, 2);
if (outputarray[0] != 0.0 || outputarray[1] != vect[10] || outputarray[2] != vect[11])
throw new Exception("CopyTo (3) test failed");
}
{
double[] outputarray = new double[collectionSize-1];
try {
vect.CopyTo(outputarray);
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
//.........这里部分代码省略.........