本文整理汇总了C#中Array类的典型用法代码示例。如果您正苦于以下问题:C# Array类的具体用法?C# Array怎么用?C# Array使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Array类属于命名空间,在下文中一共展示了Array类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetByte
public static byte GetByte (Array array, int index)
{
if (index < 0 || index >= ByteLength (array))
throw new ArgumentOutOfRangeException ("index");
return _GetByte (array, index);
}
示例2: SimpleSort
/// <summary>
/// A simple bubble sort for two arrays, limited to some region of the arrays.
/// This is a regular bubble sort, nothing fancy.
/// </summary>
public static void SimpleSort(Array array, Array items, int startingIndex, int length, IComparer comparer)
{
bool finished = false;
while (!finished)
{
bool swapped = false;
for (int g = startingIndex; g < startingIndex + length - 1; g++)
{
Object first = array.GetValue(g);
Object second = array.GetValue(g + 1);
int comparison = comparer.Compare(first, second);
if (comparison == 1)
{
Swap(g, g + 1, array, items);
swapped = true;
first = array.GetValue(g);
second = array.GetValue(g + 1);
}
}
if (!swapped)
{
finished = true;
}
}
}
示例3: SetByte
public static void SetByte (Array array, int index, byte value)
{
if (index < 0 || index >= ByteLength (array))
throw new ArgumentOutOfRangeException ("index");
_SetByte (array, index, value);
}
示例4: concat
public static Array concat( Array lhs,Array rhs )
{
Array res=Array.CreateInstance( lhs.GetType().GetElementType(),lhs.Length+rhs.Length );
Array.Copy( lhs,0,res,0,lhs.Length );
Array.Copy( rhs,0,res,lhs.Length,rhs.Length );
return res;
}
示例5: BlockCopy
public static void BlockCopy(Array src, int srcOffset, Array dst, int dstOffset, int count)
{
for (var i = 0; i < count; i++)
{
dst[i + dstOffset] = src[i + srcOffset];
}
}
示例6: decryptWithForce
//Decrypt specified cypher with force
public string decryptWithForce(string encryptedMessage)
{
byte[] originalMessageInAscii = Encoding.ASCII.GetBytes(encryptedMessage);
byte[] changedMessage = new Array(originalMessageInAscii.GetLength());
int length = originalMessageInAscii.GetLength();
//Checks each letter of the alphabet (lower case only)
for(int i = 0; i < 26; i++)
{
//Shifts ascii value in originalMessage by i to check
for (int j = 0; j < length; j++)
{
changedMessage[j] = originalMessageInAscii[j] + i;
if
Console.WriteLine(Encoding.ASCII.GetString(changedMessage, 0, length));
}
}
/*
foreach (byte b in messageInAscii)
{
Console.WriteLine(b);
}*/
}
示例7: InitializeArray
public static void InitializeArray (Array array, RuntimeFieldHandle fldHandle)
{
if ((array == null) || (fldHandle.Value == IntPtr.Zero))
throw new ArgumentNullException ();
InitializeArray (array, fldHandle.Value);
}
示例8: BlockCopy
public static void BlockCopy (Array src, int srcOffset, Array dst, int dstOffset, int count)
{
if (src == null)
throw new ArgumentNullException ("src");
if (dst == null)
throw new ArgumentNullException ("dst");
if (srcOffset < 0)
throw new ArgumentOutOfRangeException ("srcOffset", Locale.GetText(
"Non-negative number required."));
if (dstOffset < 0)
throw new ArgumentOutOfRangeException ("dstOffset", Locale.GetText (
"Non-negative number required."));
if (count < 0)
throw new ArgumentOutOfRangeException ("count", Locale.GetText (
"Non-negative number required."));
// We do the checks in unmanaged code for performance reasons
bool res = InternalBlockCopy (src, srcOffset, dst, dstOffset, count);
if (!res) {
// watch for integer overflow
if ((srcOffset > ByteLength (src) - count) || (dstOffset > ByteLength (dst) - count))
throw new ArgumentException (Locale.GetText (
"Offset and length were out of bounds for the array or count is greater than " +
"the number of elements from index to the end of the source collection."));
}
}
示例9: Copy
/// <summary>
///
/// </summary>
public static void Copy(Array sourceArray, int sourceIndex, Array destinationArray, int destinationIndex, int length)
{
for (int s = 0, d = destinationIndex; s < length; s++, d++)
{
sourceArray.SetValue(destinationArray.GetValue(d), s + sourceIndex);
}
}
示例10: read_config
public static string read_config(Array path, string default_val)
{
Hashtable current_crumb = mvid_config;
foreach (string v in path)
{
if (current_crumb[v] != null)
{
if (current_crumb[v].GetType() == typeof(Hashtable))
{
current_crumb = (Hashtable)current_crumb[v];
}
else
{
return current_crumb[v].ToString();
}
}
else
{
if (default_val != null)
{
return default_val;
}
return null;
}
}
return current_crumb.Values.ToString();
}
示例11: ArrayInfo
static void ArrayInfo(String name, Array a)
{
Console.Write("{0} has length={1} rank={2} [", name, a.Length, a.Rank);
for (int i = 0, stop=a.Rank; i<stop; i++)
Console.Write(" {0}", a.GetLength(i));
Console.WriteLine(" ]");
}
示例12: ArrayLength
static long ArrayLength(Array array, int i)
{
long n = 1;
for ( ; i < array.Rank; i++ )
n *= array.GetLength(i);
return n;
}
示例13: CopyTo
public virtual void CopyTo(Array array, int index)
{
if (array == null)
{
throw new ArgumentNullException("array");
}
if (index < 0)
{
throw new ArgumentOutOfRangeException("index");
}
if ((array.Length - index) < this._size)
{
throw new ArgumentException();
}
int num = 0;
if (array is object[])
{
object[] objArray = (object[])array;
while (num < this._size)
{
objArray[num + index] = this._array[(this._size - num) - 1];
num++;
}
}
else
{
while (num < this._size)
{
array.SetValue(this._array[(this._size - num) - 1], (int)(num + index));
num++;
}
}
}
示例14:
// Implement the ICollection interface.
void ICollection.CopyTo(Array array, int index)
{
lock(this)
{
list.CopyTo(array, index);
}
}
示例15: CopyTo
public void CopyTo (Array dest, int index)
{
/* XXX this is kind of gross and inefficient
* since it makes a copy of the superclass's
* list */
object[] values = BaseGetAllValues();
values.CopyTo (dest, index);
}