Guest User

Untitled

a guest
Feb 18th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. static void array_type<type>(type idx,type id)
  2. where type : class,ICollection
  3. {
  4.  
  5. Console.WriteLine(idx[0]);//idx[0];と書きたい。
  6.  
  7.  
  8. //foreach(var x in idx)
  9. //{
  10. // Console.WriteLine(x);
  11. //}
  12.  
  13. //for(int i=0; i< idx.Count; i++)
  14. //{
  15.  
  16. //}
  17.  
  18. }
  19. static void Main(string[] args)
  20. {
  21.  
  22. //dtest a = () => { Console.WriteLine("delegate"); };
  23.  
  24. //int[] str = new int[] {1,2,3,4,5,6,7,8,9,10};
  25. string[] str = new string[3] { "aaa", "bb", "ccc" };
  26. string[] str2 = new string[3] { "aaavvvvvvvvvvv", "bb", "ccc" };
  27.  
  28.  
  29. array_type<string[]>(str,str2);
  30.  
  31. static void ArrayTypeA<T>(T idx)
  32. where T : IList
  33. {
  34. for (int i = 0; i < idx.Count; ++i)
  35. {
  36. Debug.WriteLine($"A. idx[{i}] = " + idx[i]);
  37. }
  38. }
  39.  
  40. static void ArrayTypeB<T>(IList<T> idx)
  41. where T : IEquatable<T>, IComparable<T>
  42. {
  43. for (int i = 0; i < idx.Count; ++i)
  44. {
  45. Debug.WriteLine($"B: idx[{i}] = " + idx[i]);
  46. }
  47.  
  48. Debug.WriteLine("idx[0] equals idx[1]: " + idx[0].Equals(idx[1]));
  49. Debug.WriteLine("idx[0] compareTo idx[1]:" + idx[0].CompareTo(idx[1]));
  50. }
  51.  
  52. public void Test()
  53. {
  54. Debug.WriteLine("List<string>");
  55. var list = new List<string>() { "A1", "A2" };
  56. ArrayTypeA(list);
  57. ArrayTypeB(list);
  58.  
  59. Debug.WriteLine("string[]");
  60. var array = new string[] { "BC", "BC" };
  61. ArrayTypeA(array);
  62. ArrayTypeB(array);
  63. }
Add Comment
Please, Sign In to add comment