/[gr2lib]/trunk/gr2lib/core/helpers/arraytostring.cs
ViewVC logotype

Annotation of /trunk/gr2lib/core/helpers/arraytostring.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 96 - (hide annotations) (download)
Sat Jul 17 05:11:13 2010 UTC (9 years, 2 months ago) by william
File size: 1130 byte(s)
bulk commit:

*Update structs to use simple datatypes
*Add new Classes, etc, etc

1 william 67 using System;
2     using System.Collections.Generic;
3     using System.Collections;
4     using System.Text;
5    
6     namespace gr2lib.core.helpers
7     {
8     /// <summary>
9     /// Converts an array to a string representation
10     /// </summary>
11     /// <typeparam name="E">Element Type</typeparam>
12     /// <typeparam name="T">Array Type</typeparam>
13 william 96 public class arraytostring<E, A>
14     where A : IEnumerable<E>
15     where E : IConvertible
16 william 67 {
17 william 96
18     private int ConvertType(E value)
19     {
20     try
21     {
22     return Convert.ToInt32(value.ToString(),10);
23     }
24     catch
25     {
26     return Convert.ToInt32(value.ToString(), 16);
27     }
28    
29     }
30    
31 william 67 private string _array_string = "";
32 william 96 public arraytostring(A array) { int i = 0; foreach (E e in array) { if (i == 0) { _array_string = _array_string + "0x" + ConvertType(e).ToString("X8"); } else { _array_string = _array_string + " " + "0x" + ConvertType(e).ToString("X8"); } i++; } }
33 william 67 public override string ToString() { return _array_string; }
34     }
35     }

  ViewVC Help
Powered by ViewVC 1.1.22