本文整理汇总了C#中System.Array.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# Array.ToString方法的具体用法?C# Array.ToString怎么用?C# Array.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Array
的用法示例。
在下文中一共展示了Array.ToString方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RenderArray
/// <summary>
/// Dump the contents of an array into a string builder
/// </summary>
static void RenderArray(Array array, StringBuilder buffer)
{
if (array == null)
buffer.Append(SystemInfo.NullText);
else
{
if (array.Rank != 1)
buffer.Append(array.ToString());
else
{
buffer.Append("{");
var len = array.Length;
if (len > 0)
{
RenderObject(array.GetValue(0), buffer);
for (var i = 1; i < len; i++)
{
buffer.Append(", ");
RenderObject(array.GetValue(i), buffer);
}
}
buffer.Append("}");
}
}
}
示例2: RenderArray
/// <summary>
/// Render the array argument into a string
/// </summary>
/// <param name="rendererMap">The map used to lookup renderers</param>
/// <param name="array">the array to render</param>
/// <param name="writer">The writer to render to</param>
/// <remarks>
/// <para>
/// For a one dimensional array this is the
/// array type name, an open brace, followed by a comma
/// separated list of the elements (using the appropriate
/// renderer), followed by a close brace. For example:
/// <c>int[] {1, 2, 3}</c>.
/// </para>
/// <para>
/// If the array is not one dimensional the
/// <c>Array.ToString()</c> is returned.
/// </para>
/// </remarks>
private void RenderArray(RendererMap rendererMap, Array array, TextWriter writer)
{
if (array.Rank != 1)
{
writer.Write(array.ToString());
}
else
{
writer.Write(array.GetType().Name + " {");
int len = array.Length;
if (len > 0)
{
rendererMap.FindAndRender(array.GetValue(0), writer);
for(int i=1; i<len; i++)
{
writer.Write(", ");
rendererMap.FindAndRender(array.GetValue(i), writer);
}
}
writer.Write("}");
}
}
示例3: CompareUnSorted
private void CompareUnSorted(Array a, Array b)
{
string msg = string.Format("Failed while comparing(Array a ={0} ({1}), Array b = {2} ({3}))]", a.ToString(), a.GetType().FullName, b.ToString(), b.GetType().FullName);
foreach (object item in a) {
if (Array.IndexOf(b, item) < 0) //b does not contain the current item.
Assert.Fail(msg);
}
foreach (object item in b) {
if (Array.IndexOf(a, item) < 0) //a does not contain the current item.
Assert.Fail(msg);
}
}
示例4: RenderArray
/// <summary>
/// Render the array argument into a string
/// </summary>
/// <param name="rendererMap">The map used to lookup renderers</param>
/// <param name="array">the array to render</param>
/// <returns>the string representation of the array</returns>
/// <remarks>
/// <para>For a one dimensional array this is the
/// array type name, an open brace, followed by a comma
/// separated list of the elements (using the appropriate
/// renderer), followed by a close brace. For example:
/// <c>int[] {1, 2, 3}</c>.</para>
/// <para>If the array is not one dimensional the
/// <c>Array.ToString()</c> is returned.</para>
/// </remarks>
virtual protected string RenderArray(RendererMap rendererMap, Array array)
{
if (array.Rank != 1)
{
return array.ToString();
}
else
{
StringBuilder buffer = new StringBuilder(array.GetType().Name + " {");
int len = array.Length;
if (len > 0)
{
buffer.Append(rendererMap.FindAndRender(array.GetValue(0)));
for(int i=1; i<len; i++)
{
buffer.Append(", ").Append(rendererMap.FindAndRender(array.GetValue(i)));
}
}
return buffer.Append("}").ToString();
}
}
示例5: RenderArray
/// <summary>
/// Dump the contents of an array into a string builder
/// </summary>
private static void RenderArray(Array array, StringBuilder buffer)
{
if (array == null)
{
buffer.Append(nullText);
}
else
{
if (array.Rank != 1)
{
buffer.Append(array.ToString());
}
else
{
buffer.Append("{");
int len = array.Length;
if (len > 0)
{
RenderObject(array.GetValue(0), buffer);
for (int i = 1; i < len; i++)
{
buffer.Append(", ");
RenderObject(array.GetValue(i), buffer);
}
}
buffer.Append("}");
}
}
}
示例6: Compare
/// <summary>Compare two Object Arrays.
/// <param name="a">First array.</param>
/// <param name="b">Second array.</param>
/// <param name="Sorted">Used to indicate if both arrays are sorted.</param>
/// </summary>
protected bool Compare(Array a, Array b)
{
Assert.AreEqual(b, a);
//signal that the Compare method has been called
this._testCase.CompareInvoked=true;
//a string that holds the description of the objects for log
string ObjectData;
//check if both objects are null
if ( (a == null && b == null) )
{
ObjectData = "Array a = null, Array b = null";
this._testCase.Success = true; //both objects are null, TestCase Succeed
LogCompareResult(ObjectData);
return this._testCase.Success;
}
//Check if one of the objects is null.
//(If both were null, we wouldn't have reached here).
if (a == null || b == null)
{
string aData = (a==null) ? "null" : "'" + a.ToString() + "' (" + a.GetType().FullName + ")";
string bData = (b==null) ? "null" : "'" +b.ToString() + "' (" + b.GetType().FullName + ")";
ObjectData = "Array a = " + aData + ", Array b = " + bData;
this._testCase.Success = false; //objects are different, testCase Failed.
LogCompareResult(ObjectData);
return this._testCase.Success;
}
//check if both arrays are of the same rank.
if (a.Rank != b.Rank)
{
this._testCase.Success = false;
ObjectData = string.Format("Array a.Rank = {0}, Array b.Rank = {1}", a.Rank, b.Rank);
LogCompareResult(ObjectData);
return this._testCase.Success;
}
//Do not handle multi dimentional arrays.
if (a.Rank != 1)
{
this._testCase.Success = false;
ObjectData = "Multi-dimension array comparison is not supported";
LogCompareResult(ObjectData);
return this._testCase.Success;
}
//Check if both arrays are of the same length.
if (a.Length != b.Length)
{
this._testCase.Success = false;
ObjectData = string.Format("Array a.Length = {0}, Array b.Length = {1}", a.Length, b.Length);
LogCompareResult(ObjectData);
return this._testCase.Success;
}
ObjectData = "Array a.ToString() = '" + a.ToString() + "'(" + a.GetType().FullName + ") Array b.ToString = '" + b.ToString() + "'(" + b.GetType().FullName + ")";
//Compare elements of the Array.
int iLength = a.Length;
for (int i=0; i<iLength; i++)
{
object aValue = a.GetValue(i);
object bValue = b.GetValue(i);
if (aValue == null && bValue == null)
{
continue;
}
if (aValue == null || bValue == null || !aValue.Equals(bValue) )
{
string aData = (aValue==null) ? "null" : "'" + aValue.ToString() + "' (" + aValue.GetType().FullName + ")";
string bData = (bValue==null) ? "null" : "'" + bValue.ToString() + "' (" + bValue.GetType().FullName + ")";
ObjectData = string.Format("Array a[{0}] = {1}, Array b[{0}] = {2}", i, aData, bData);
this._testCase.Success = false; //objects are different, testCase Failed.
LogCompareResult(ObjectData);
return this._testCase.Success;
}
}
this._testCase.Success = true;
LogCompareResult(ObjectData);
return this._testCase.Success;
}
示例7: CompareUnSorted
private void CompareUnSorted(Array a, Array b)
{
string msg = string.Format("Failed while comparing(Array a ={0} ({1}), Array b = {2} ({3}))]", a.ToString(), a.GetType().FullName, b.ToString(), b.GetType().FullName);
foreach (object item in a)
{
if (Array.IndexOf(b, item) < 0) //b does not contain the current item.
{
this.Fail(msg);
return;
}
}
foreach (object item in b)
{
if (Array.IndexOf(a, item) < 0) //a does not contain the current item.
{
this.Fail(msg);
return;
}
}
//b contains all items of a, and a contains all items of b.
this.Pass(msg);
}