本文整理汇总了C#中System.Array.CopyTo方法的典型用法代码示例。如果您正苦于以下问题:C# Array.CopyTo方法的具体用法?C# Array.CopyTo怎么用?C# Array.CopyTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Array
的用法示例。
在下文中一共展示了Array.CopyTo方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CombineArrays
private static Array CombineArrays(Array arr1, Array arr2)
{
if (arr1 == null)
return arr2;
if (arr2 == null)
return arr1;
Array newArr = Array.CreateInstance(arr1.GetType().GetElementType(), arr1.Length + arr2.Length);
arr1.CopyTo(newArr, 0);
arr2.CopyTo(newArr, arr1.Length);
return newArr;
}
示例2: Join
//�ΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡ��������Ӻ���
public static Array Join(Array list1, Array list2, Type arrayType)
{
Array list = null;
if (list1 != null && list2 != null)
{
list = Activator.CreateInstance(arrayType, list1.Length + list2.Length) as Array;
if (list != null)
{
list1.CopyTo(list, 0);
list2.CopyTo(list, list1.Length);
}
}
return list;
}
示例3: Add
public static Array Add(Array aFirst, Array aSecond)
{
if (aFirst == null)
{
return aSecond.Clone() as Array;
}
if (aSecond == null)
{
return aFirst.Clone() as Array;
}
Type typeFirst = aFirst.GetType().GetElementType();
Type typeSecond = aSecond.GetType().GetElementType();
System.Diagnostics.Debug.Assert(typeFirst == typeSecond);
Array aNewArray = Array.CreateInstance(typeFirst, aFirst.Length + aSecond.Length);
aFirst.CopyTo(aNewArray, 0);
aSecond.CopyTo(aNewArray, aFirst.Length);
return aNewArray;
}
示例4:
void ICollection.CopyTo (Array array, int index)
{
// assuming that Nodes is a correct collection.
array.CopyTo (Nodes.ToArray (typeof(XmlAttribute)), index);
}
示例5: CopyTo
public void CopyTo(Array array, int index)
{
array.CopyTo(array, index);
}
示例6: RotateArrayLeft
/// <summary>
/// Fills dest with a rotated version of source.
/// </summary>
/// <param name="source">The source array.</param>
/// <param name="dest">The dest array, which must have the same length and underlying type
/// as source.</param>
/// <param name="rotation">The number of elements to rotate to the left by.</param>
private static void RotateArrayLeft(Array source, Array dest, int rotation)
{
if (source.Length != dest.Length)
{
throw new ArgumentException("source and dest lengths differ.");
}
if (rotation == 0)
{
source.CopyTo(dest, 0);
}
else
{
for (int i = 0; i < source.Length; ++i)
{
dest.SetValue(source.GetValue((rotation + i) % source.Length), i);
}
}
}
示例7: AppendToArray
public static object[] AppendToArray(Array currentListeners, object listener) {
var elemType = currentListeners.GetType().GetElementType();
var newListeners = Array.CreateInstance(elemType, currentListeners.Length + 1);
currentListeners.CopyTo(newListeners, 0);
newListeners.SetValue(listener, currentListeners.Length);
return (object[]) newListeners;
}
示例8: AcquireWriteLock_ReadWrite_LocksCorrectly
public void AcquireWriteLock_ReadWrite_LocksCorrectly()
{
var name = Guid.NewGuid().ToString();
Random r = new Random();
int bufSize = 1024;
byte[] data = new byte[bufSize];
byte[] readBuf = new byte[bufSize];
bool readIsFirst = false;
bool readBlocked = false;
int syncValue = 0;
// Fill with random data
r.NextBytes(data);
using (var sma = new Array<byte>(name, bufSize))
{
// Acquire write lock early
sma.AcquireWriteLock();
using (var smr = new Array<byte>(name))
{
var t1 = Task.Factory.StartNew(() =>
{
if (System.Threading.Interlocked.Exchange(ref syncValue, 1) == 0)
readIsFirst = true;
// Should block until write lock is released
smr.AcquireReadLock();
if (System.Threading.Interlocked.Exchange(ref syncValue, 3) == 4)
readBlocked = true;
smr.CopyTo(readBuf);
smr.ReleaseReadLock();
});
System.Threading.Thread.Sleep(10);
var t2 = Task.Factory.StartNew(() =>
{
var val = System.Threading.Interlocked.Exchange(ref syncValue, 2);
if (val == 0)
readIsFirst = false;
else if (val == 3)
readBlocked = false;
System.Threading.Thread.Sleep(10);
sma.Write(data);
System.Threading.Interlocked.Exchange(ref syncValue, 4);
sma.ReleaseWriteLock();
});
Task.WaitAll(t1, t2);
Assert.IsTrue(readIsFirst, "The read thread did not enter first.");
Assert.IsTrue(readBlocked, "The read thread did not block.");
// Check data was written before read
for (var i = 0; i < readBuf.Length; i++)
{
Assert.AreEqual(data[i], readBuf[i]);
}
}
}
}
示例9: CopyTo_NullArray_ThrowsException
public void CopyTo_NullArray_ThrowsException()
{
var name = Guid.NewGuid().ToString();
using (var sma = new Array<int>(name, 10))
{
bool exceptionThrown = false;
try
{
sma.CopyTo(null);
}
catch (ArgumentNullException)
{
exceptionThrown = true;
}
Assert.IsTrue(exceptionThrown, "null buffer should result in ArgumentNullException");
}
}
示例10: In
/// <summary>
/// Creates an <see cref="InPredicate"/>.
/// </summary>
/// <param name="field">Database field.</param>
/// <param name="values">List of values.</param>
/// <param name="negate">Specifies whether the predicate is negated (NOT IN).</param>
/// <returns>InPredicate.</returns>
/// <remarks>Creates an IN predicate that determines if a field matches any value in a list.</remarks>
public static InPredicate In(IDbColumn field, Array values, bool negate)
{
object[] objValues = new object[values.Length];
values.CopyTo(objValues, 0);
return In(field, objValues, negate);
}
示例11: setRow
public void setRow(int row, Array vals)
{
vals.CopyTo (boxes, row * 4);
}
示例12: TestWriteToAndReadFrom
public void TestWriteToAndReadFrom()
{
using (var map = new MemoryMapStream())
{
using (var memoryStream = new MemoryStream())
{
using (var array = new Array<int>(map, 10))
{
for (var i = 0; i < array.Length; i++)
{
array[i] = i + 100;
}
array.CopyTo(memoryStream);
memoryStream.Seek(0, SeekOrigin.Begin);
using (var array1 = new Array<int>(map, array.Length))
{
array1.CopyFrom(memoryStream);
for (var i = 0; i < array.Length; i++)
{
Assert.AreEqual(array[i], array1[i]);
}
}
}
}
}
using (var map = new MemoryMapStream())
{
using (var memoryStream = new MemoryStream())
{
using (var array = new Array<int>(map, 10000, 32, 32, 2))
{
for (var i = 0; i < array.Length; i++)
{
array[i] = i + 100;
}
array.CopyFrom(memoryStream);
memoryStream.Seek(0, SeekOrigin.Begin);
using (var array1 = new Array<int>(map, array.Length))
{
array.CopyFrom(memoryStream);
for (var i = 0; i < array.Length; i++)
{
Assert.AreEqual(array[i], array1[i]);
}
}
}
}
}
}