本文整理匯總了C#中System.Array.CreateElementInstance方法的典型用法代碼示例。如果您正苦於以下問題:C# Array.CreateElementInstance方法的具體用法?C# Array.CreateElementInstance怎麽用?C# Array.CreateElementInstance使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Array
的用法示例。
在下文中一共展示了Array.CreateElementInstance方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: WriteFixedArray
private void WriteFixedArray(Array arr, int constantStringLength, BinaryWriter writer)
{
// Fixed-size arrays have no header at all. Just all the values one after each other.
for (var i = 0; i < arr.Length; i++)
{
var value = arr.GetValue(i);
if (value == null)
value = arr.CreateElementInstance();
Serialize(value, constantStringLength, writer);
}
}
示例2: WriteArray2
private void WriteArray2(Array arr, int constantStringLength, BinaryWriter writer)
{
// only dynamic, 0-based multidimensional arrays are supported.
WriteArrayRank(2, writer);
int i = arr.GetLength(0);
int j = arr.GetLength(1);
WriteArrayLength(j, 0, writer);
WriteArrayLength(i, 0, writer);
for (int jj = 0; jj < j; jj++)
{
for (int ii = 0; ii < i; ii++)
{
var value = arr.GetValue(ii, jj);
if (value == null)
value = arr.CreateElementInstance();
Serialize(value, constantStringLength, writer);
}
}
}