这个各位达人能不能帮下?

starlightshadow 2008-10-19 12:25:45
using System;
enum Color{Red,Yellow,Blue,Green,Purple,Black,White
};
class Test{
public static void Main(){
Color color;
color=(Color)3;
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]);
}
}
要正确的的,以上是编译不过去的,我是新手刚到这一章节所以想半天也弄不明白,所以请各位达人在给出正确的答案同时能不能给我讲解一下啊,谢谢啦
...全文
75 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
starlightshadow 2008-10-19
  • 打赏
  • 举报
回复
本人知道最后的结果就是把枚举中的三个整型变量给输出,但是就是不知从何下手.
music_xu 2008-10-19
  • 打赏
  • 举报
回复
Tostring()&tostring();
li45214521 2008-10-19
  • 打赏
  • 举报
回复
C/c++转过来的?
starlightshadow 2008-10-19
  • 打赏
  • 举报
回复
哦,受教了,谢谢指点
superliu1122 2008-10-19
  • 打赏
  • 举报
回复
你问题本义是什么?
你这个程序想实现什么样的功能
编译通不过是因为color不是数组,仔细看看错误信息
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]);
superliu1122 2008-10-19
  • 打赏
  • 举报
回复
是ToString()
starlightshadow 2008-10-19
  • 打赏
  • 举报
回复
using System;
using System.Collections;
enum Color:short{
Red,Yellow,Blue,Green,Purple,Black,While
};
class Test
{
static void Main(string[] args){
for(int i=0;i<7;i++)
{
Console.WriteLine("The value of color[0] is:{0}",((Color)i).Tostring());
}
Console.ReadLine();
}
}
error CS0117:"Color"并不包含"Tostring"的定义楼上的你的行不通啊,而且和我的问题本义有些不一致哦
lklcool 2008-10-19
  • 打赏
  • 举报
回复

using System;
using System.Collections;
enum Color:short
{
Red,
Yellow, Blue, Green, Purple, Black, White
};
class Test
{
static void Main(string [] args)
{
for (int i = 0; i < 7; i++)
{
Console.WriteLine("The value of color[0] is:{0}", ((Color)i).ToString());
}
Console.ReadLine();
}
}
starlightshadow 2008-10-19
  • 打赏
  • 举报
回复
是啊,应该怎么解决嘛
丛晓男 2008-10-19
  • 打赏
  • 举报
回复
color_arr=(Color[])int_arr;
这句应该有问题吧,应该对每个元素分别转换

110,539

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧