using System;
enum Color{
red,yellow,blue,green
};
class Test
{
public static void Main(){
Color[] color_arr=new Color[3];
int[] int_arr=new int[]{1,2,3};
color_arr=(Color[]) int_arr;
Console.WriteLine("The value of color[0] is:{0}",Color[0]);
Console.WriteLine("The value of color[1] is:{0}",Color[1]);
Console.WriteLine("The value of color[2] is:{0}",Color[2]);
}
}
教程中,显示转换的纠错题目,请指教,谢谢。
enum Color{
red,yellow,blue,green
};
class Test
{
public static void Main(){
Color[] color_arr=new Color[3];
int[] int_arr=new int[]{1,2,3};
color_arr=(Color[]) int_arr;
Console.WriteLine("The value of color[0] is:{0}",Color[0]);
Console.WriteLine("The value of color[1] is:{0}",Color[1]);
Console.WriteLine("The value of color[2] is:{0}",Color[2]);
}
}
教程中,显示转换的纠错题目,请指教,谢谢。
public static void Main(){
Color[] color_arr=new Color[3];
int[] int_arr=new int[]{1,2,3};
for(int i = 0; i < int_arr.Length; i ++)
{
if(i < color_arr.Length)
{
color_arr[i] = (Color)int_arr[i];
}
}
color_arr=(Color[]) int_arr;
Console.WriteLine("The value of color[0] is:{0}",Color[0]);
Console.WriteLine("The value of color[1] is:{0}",Color[1]);
Console.WriteLine("The value of color[2] is:{0}",Color[2]);