本文整理汇总了C#中DoubleVector.Add方法的典型用法代码示例。如果您正苦于以下问题:C# DoubleVector.Add方法的具体用法?C# DoubleVector.Add怎么用?C# DoubleVector.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DoubleVector
的用法示例。
在下文中一共展示了DoubleVector.Add方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: method
public override void method(ref double[] vpre, DoubleVector vpost)
{
Assert(vpre[0], 1.0);
vpre[0] = 2.0;
Assert(vpost.Count, 2);
vpost.Add(1.0);
}
示例2: 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
//.........这里部分代码省略.........
示例3: Main
public static void Main() {
{
double[] v;
csharp_prepost.globalfunction(out v);
Assert(v.Length, 3);
Assert(v[0], 0.0);
Assert(v[1], 1.1);
Assert(v[2], 2.2);
}
{
double[] v;
new PrePostTest(out v);
Assert(v.Length, 2);
Assert(v[0], 3.3);
Assert(v[1], 4.4);
}
{
double[] v;
PrePostTest p = new PrePostTest();
p.method(out v);
Assert(v.Length, 2);
Assert(v[0], 5.5);
Assert(v[1], 6.6);
}
{
double[] v;
PrePostTest.staticmethod(out v);
Assert(v.Length, 2);
Assert(v[0], 7.7);
Assert(v[1], 8.8);
}
{
PrePost3_Derived p = new PrePost3_Derived();
double[] vpre = new double[] { 1.0 };
DoubleVector vpost = new DoubleVector();
vpost.Add(3.0);
vpost.Add(4.0);
p.method(ref vpre, vpost);
Assert(vpre[0], 2.0);
Assert(vpost.Count, 3);
}
{
PrePost3_Derived p = new PrePost3_Derived();
double[] vpre = new double[] { 1.0 };
DoubleVector vpost = new DoubleVector();
vpost.Add(3.0);
vpost.Add(4.0);
int size = p.methodint(ref vpre, vpost);
Assert(vpre[0], 2.0);
Assert(vpost.Count, 3);
Assert(size, 3);
}
// Check attributes are generated for the constructor helper function
{
CsinAttributes c = new CsinAttributes(5);
Assert(c.getVal(), 500);
Type type = typeof(CsinAttributes);
{
MethodInfo member = (MethodInfo)type.GetMember("SwigConstructCsinAttributes", BindingFlags.NonPublic | BindingFlags.Static)[0];
if (Attribute.GetCustomAttribute(member, typeof(CustomIntPtrAttribute)) == null)
throw new Exception("No CustomIntPtr attribute for " + member.Name);
ParameterInfo parameter = member.GetParameters()[0]; // expecting one parameter
if (parameter.Name != "val")
throw new Exception("Incorrect parameter name");
Attribute attribute = Attribute.GetCustomAttributes(parameter)[0];
if (attribute.GetType() != typeof(CustomIntAttribute))
throw new Exception("Expecting CustomInt attribute");
}
}
// Dates
{
// pre post typemap attributes example
System.DateTime dateIn = new System.DateTime(2011, 4, 13);
System.DateTime dateOut = new System.DateTime();
// Note in calls below, dateIn remains unchanged and dateOut
// is set to a new value by the C++ call
csharp_prepostNamespace.Action action = new csharp_prepostNamespace.Action(dateIn, out dateOut);
if (dateOut != dateIn)
throw new Exception("dates wrong");
dateIn = new System.DateTime(2012, 7, 14);
action.doSomething(dateIn, out dateOut);
if (dateOut != dateIn)
throw new Exception("dates wrong");
System.DateTime refDate = new System.DateTime(1999, 12, 31);
if (csharp_prepost.ImportantDate != refDate)
throw new Exception("dates wrong");
refDate = new System.DateTime(1999, 12, 31);
csharp_prepost.ImportantDate = refDate;
System.DateTime importantDate = csharp_prepost.ImportantDate;
if (importantDate != refDate)
throw new Exception("dates wrong");
System.DateTime christmasEve = new System.DateTime(2000, 12, 24);
//.........这里部分代码省略.........