Add ToArray test for C# std::vector wrapper
diff --git a/CHANGES.current b/CHANGES.current
index 0aad216..07ab418 100644
--- a/CHANGES.current
+++ b/CHANGES.current
@@ -7,6 +7,9 @@
 Version 4.0.0 (in progress)
 ===========================
 
+2018-01-12: Liryna
+            [C#] Patch #1128. Add ToArray function to std::vector wrappers.
+
 2018-01-12: wsfulton
             [Java] Fix issue #1156. Add missing throws clause for interfaces when using the
             %interface family of macros.
diff --git a/Examples/test-suite/csharp/li_std_vector_runme.cs b/Examples/test-suite/csharp/li_std_vector_runme.cs
index 453faa6..0c6211c 100644
--- a/Examples/test-suite/csharp/li_std_vector_runme.cs
+++ b/Examples/test-suite/csharp/li_std_vector_runme.cs
@@ -177,6 +177,17 @@
         if (doubleArray[i] != dvCopy[i])
           throw new Exception("Copy constructor failed, index:" + i);
       }
+      if (dvCopy.Count != doubleArray.Length)
+        throw new Exception("Copy constructor lengths mismatch");
+
+      // ToArray test
+      double[] dvArray = dv.ToArray();
+      for (int i=0; i<doubleArray.Length; i++) {
+        if (doubleArray[i] != dvArray[i])
+          throw new Exception("ToArray failed, index:" + i);
+      }
+      if (dvArray.Length != doubleArray.Length)
+        throw new Exception("ToArray lengths mismatch");
     }
     {
       // Repeat() test
diff --git a/Lib/csharp/std_vector.i b/Lib/csharp/std_vector.i
index 95543c2..a69cb63 100644
--- a/Lib/csharp/std_vector.i
+++ b/Lib/csharp/std_vector.i
@@ -115,7 +115,7 @@
   }
 
   public $typemap(cstype, CTYPE)[] ToArray() {
-    $typemap(cstype, CTYPE)[] array = new $typemap(cstype, CTYPE)[Count];
+    $typemap(cstype, CTYPE)[] array = new $typemap(cstype, CTYPE)[this.Count];
     this.CopyTo(array);
     return array;
   }