-1

I am trying to generate an array of 2 character length of alphanumeric (0-9, A-Z) characters without having to hardcode all of the values. Ex output: 00, 01,..., 09, 90, 91,..., 99, A0, A1,..., A9,AA,..., ZZ

I found a link to generate an array of letters with less work, but I am still unsure of how to do this for a 2D array. I'm new to working with multidimensional arrays. Thanks!

Generating an array of letters in the alphabet

Community
  • 1
  • 1
  • Can you show us what you want the array to look like? – juharr Jul 08 '15 at 17:58
  • Hint: char a = (char)65;//this will give you 'A' – Maxqueue Jul 08 '15 at 17:59
  • Using loops or linq it's fairly easy. What have you tried so far? – Zohar Peled Jul 08 '15 at 18:01
  • 1
    @Maxqueue eww. I think a better piece of advice would be saying that `'A'+1 == 'B'`, `'A'+2 == 'C'`, etc. I urge you to never use `(char)65` in your code. Ever. – Jashaszun Jul 08 '15 at 18:01
  • @juharr I created a regular array of the characters, I just need the array to be 2D with the same characters: public const char[] FirstChars = new char[] {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z' }; – Shannon Morris Jul 08 '15 at 18:11
  • I don't know what you mean. Think of a 2D array as a table where the first dimension is the row number and the second is the column. You need to tell use how many rows and columns you expect and what values should be in each cell. – juharr Jul 08 '15 at 18:14
  • Can you print the sample output you are looking for? should it be like this: "1A", "1B" , ... – Hossein Narimani Rad Jul 08 '15 at 18:16
  • Or maybe you could tell use what you plan to use this 2D array for. This might be a [XY problem](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem) – juharr Jul 08 '15 at 18:17
  • @HosseinNarimaniRad Yes output would be 00,01,10,...99,A0,A1,...A9,..AA...ZZ, etc – Shannon Morris Jul 08 '15 at 18:22
  • @juharr I'm sorry- output would be 00,01,10,...99,A0,A1,...A9,..AA...ZZ, etc – Shannon Morris Jul 08 '15 at 18:22
  • That doesn't look like a 2D array, it looks like an array of two character length strings. Do you mean {{'0','0'},{'0','1'},{'1','0'},...{'9','9'},{'A','0'},{'A','1'},....{'Z','Z'}}. Basically the Cartesian product of the set of all alpha-numeric characters with itself? – juharr Jul 08 '15 at 18:26
  • @juharr you are correct, I was mistaken in needing a 2D array and I see that now. I need an array of two character length strings of the Cartesian product of the set of alphanumeric characters. I'm sorry for the confusion – Shannon Morris Jul 08 '15 at 18:39

1 Answers1

0

If you want the cartesian product of all alpha numeric characters as two character strings then you can use Linq and do the following.

string alphanumeric = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 
string[] allAlphaNumericPairs = (from a in alphanumeric
                                 from b in alphanumeric
                                 select new string(new []{a,b})).ToArray();
juharr
  • 31,741
  • 4
  • 58
  • 93