我想将字符串转换为字符数组。此外,字符数组中的值必须使用枚举转换为数值。作为整数返回的值必须存储在整数数组中。
我的编码是:
enum alphabets { a = 1,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}
static void Main()
{
int row,column;
String value1;
Console.WriteLine("Enter string");
string UserString= Console.ReadLine();
int len = UserString.Length;
if (len % 2 == 0)
{
row = len / 2;
column = len / 2;
PrintMatrix(row, column, len, value1);
}
Console.ReadKey();
}
static void PrintMatrix(int row, int column, int len, string value1)
{
Console.WriteLine("Matrix");
string mat_row = value1.Substring(0, row);
string mat_col = value1.Substring(row, len - row);
GenNum(mat_row,len);
GenNum(mat_col,len);
}
static void GenNum(string val, int len)
{
string res = val;
foreach (char c in res)
{
string name = c.ToString();
alphabets parsed = (alphabets)Enum.Parse(typeof(alphabets), name);
int NumGen = (int)parsed;
Console.WriteLine (NumGen);
}
}
我尝试将其转换string name
为char[]
如下所示的错误:
所以,我试图改变NumGen as int[]
,它说这样的错误:
我该如何解决?