I am trying to convert a letter to its alphabet numerical order for example if I have an 'A' it will give me 00 or a 'C' 02
How can I code this in c# ?
EDIT : This is what I tried
I created this class :
public class AlphabetLetter
{
public char Letter {get; set;}
public int Rank {get; set;}
}
Those Two Lists :
public List<char> Letters = new List<char> {
'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'
};
public List<int> Ranks = new List<int> {
00,01,02,04,05,06,07,08,09,10,11,12,13,
14,15,16,17,18,19,20,21,22,23,24,25
};
public List<AlphabetLetter> Alphabet = new List<AlphabetLetter>( );
I created the Alphabet in my Constructor :
for (int i = 0; i < 25; i++)
{
Alphabet.Add(new AlphabetLetter { Rank = Ranks[i], Letter = Letters[i] });
And tried to match a char with this function :
public int Numberize(char Letter)
{
if (Letter != null)
{
foreach (AlphabetLetter _letter in Alphabet)
{
if (Letter == _letter.Letter)
{
return _letter.Rank;
}
else
{
return 896;
}
}
}
else {
return 999;
}
}
}
But this method is not working and is too tedious.
Any suggestions?