对于这样的一个枚举类型:enum Color:byte{Red,Green,Blue,Orange}string[] ss=Enum.GetNames(typeof(Color));byte[] bb=Enum.GetValues(typeof(Color));试写一段程序显示出枚举类型中定义的所有符号名称以及它们对应的数值。

题目

对于这样的一个枚举类型:

enum Color:byte{

Red,

Green,

Blue,

Orange

}

string[] ss=Enum.GetNames(typeof(Color));

byte[] bb=Enum.GetValues(typeof(Color));

试写一段程序显示出枚举类型中定义的所有符号名称以及它们对应的数值。


相似考题
更多“对于这样的一个枚举类型:enum Color:byte{Red,Green,Blue,Orange}string[] ss=Enum.GetNames(typeof(Color));byte[] bb=Enum.GetValues(typeof(Color));试写一段程序显示出枚举类型中定义的所有符号名称以及它们对应的数值。”相关问题
  • 第1题:

    以下关于样式表项的定义中,错误的是:()。

    A.H1, H2 {color:red}

    B.H1 B{color:red}

    C.H1#color_red{color:red}

    DA:Active {color:red}


    参考答案:C

  • 第2题:

    publicclassBall{publicenumColor{RED,GREEN,BLUE};publicvoidfoo(){//insertcodehere{System.out.println(c);}}}Whichcodeinsertedatline14causesthefoomethodtoprintRED,GREEN,andBLUE?()

    A.for(Colorc:Color.values())

    B.for(Colorc=RED;c<=BLUE;c++)

    C.for(Colorc;c.hasNext();c.next())

    D.for(Colorc=Color[0];c<=Color[2];c++)

    E.for(Colorc=Color.RED;c<=Color.BLUE;c++)


    参考答案:A

  • 第3题:

    下列枚举类型的定义中,包含枚举值3的是( )。

    A.enumtest{RED,YELLOW,BLUE,BLACK};

    B.enumtest{RED,YELLOW=4,BLUE,BLACK);

    C.enumtest{RED=-1,YELLOW,BLUE,BLACK};

    D.enumtest{RED,YELLOW=6,BLUE,BLACK);


    正确答案:A
    A。【解析】本题主要考查枚举类型的定义,其中几个枚举值全部未赋常量值时,它们自左至右分别与整数0,1,…,n-1对应。由此可判断本题答案。

  • 第4题:

    下列枚举类型的定义中,包含枚举值3的是

    A.enum test{RED,YELLOW,BLUE,BLACK};

    B.enum test{RED,YELLOW=4,BLUE,BLACK};

    C.enum test{RED=-1,YELLOW,BLUE,BLACK};

    D.erium test{RED,YELLOW=6,BLUE,BLACK};


    正确答案:A
    解析:在枚举类型定义中,如果没有进行显式设置,则隐式设置整数值。将枚举声明中的第一个枚举值设置为O。后续所有成员的值如果没有进行显式设置,便确定为前一个成员的值加1。所以只能选择答案A)。选项B)中对应的枚举值是0,4,5,6;选项c)中对应的枚举值是-1,0,1,2;选项D)中对应的枚举值是0,6,7,8。

  • 第5题:

    已知枚举类型声明语句为: enum COLOR{WHITE,YELLOW,GREEN=5,RED,BLACK=10}; 则下列说法中错误的是

    A.枚举常量YELLOW的值为1

    B.枚举常量RED的值为6

    C.枚举常量BLACK的值为10

    D.枚举常量WHITE的值为1


    正确答案:D
    解析:枚举值是常量,不是变量。不能在程序中用赋值语句再对它赋值;枚举元素本身由系统定义了一个表示序号的数值,从0开始顺序定义为0,1,2…。所以枚举函数中对象的值应从。开始,依次加1,如果有的对象已赋值,则后面也按照前面的值依次加1的原则。

  • 第6题:

    以下选项中能正确把c1定义成结构体变量的是( )。

    A.typedef struct { int red; int red; int green; int blue; }COLOR; COLOR c1;

    B.struct color c1 { int red int red; int green int blue; };

    C.stmctcolor { int red, int green; int blue; }c1;

    D.struct { int red; int green; int blue; }c1;


    正确答案:D
    解析:因为结构体中不能出现同名的成员变量,所以选项A和B都是错误的;又因为结构体中成员的定义应该由分号隔开,所以选项C也是错误的。选项D定义了一个无名结构体,并同时定义该结构体变量c1,是正确的写法。故应该选择D。

  • 第7题:

    在下列枚举类型的定义中,包含枚举值3的是

    A.entire test(RED,YELLOW,BLUE,BLACK);

    B.entire test(RED,YELLOW,BLUE,BLACK);

    C.enum test(RED=-1,YELLOW,BLUE,BLACK);

    D.enum test(RED,YELLOW=6,BLUE,BLACK);


    正确答案:A
    解析:枚举变量中的枚举元素系统是按照常量来处理的,如果没有进行元素赋值操作,那么元素将会被系统自动从0开始自动递增地进行赋值操作,但是,如果一旦定义了某一个元素,那么系统将对下一个元素进行前一个元素的值加1操作。

  • 第8题:

    在下列程序段中,枚举变量 c1的值是()。

    enum color { red,yellow,blue=4,green,white}c1; c1=yellow; c1=white;

    A 1

    B 3

    C 5

    D 6


    正确答案:D

  • 第9题:

    The traffic lights were red when the driver reached them.To the surprise of his passenger,the ear did not slow down.Unexpectedly the passenger was thrown forward in the vehicle as the driver put on his brakes at the last moment.The car stopped just in time.
    "Sorry,I didn't notice the light.I thought it was green until I saw that it was the top light which was shining."
    This strange story is quite true.About ten men in every hundred are color blind in some way;women are luckier--only about one in two hundred suffers from color blindness.
    In some cases,a man may not be able to see deep red.He may think that red,orange and yellow are all the same as green.
    People often like one color more than others.Blue is the color of the sky and sea.Green makes us think of fields and trees.Red is the color of blood and makes some people think of danger.Black is the color of night.In the dark we cannot see what is around us so we are sometimes afraid of the unknown and do not like black as a color.

    One is considered as a color blind man if__.

    A.he can see the difference between red and deep red
    B.he can see the difference between blue and green
    C.he can't tell the difference between orange and green
    D.he thinks green is the same as blue

    答案:C
    解析:
    参见第四段。

  • 第10题:

    以下程序的输出结果是()。enumColor{Red,Green=2,Blue}staticvoidMain(string[]args){Colorc=0;Colorc1=(Color)2;Console.WriteLine("{0},{1}",c,c1);Console.Read();}

    • A、Green,Red
    • B、Red,Green
    • C、Red,Blue
    • D、Green,Blue

    正确答案:B

  • 第11题:

    package sun.scjp;  public enum Color { RED, GREEN, BLUE }  package sun.beta;  // insert code here  public class Beta {  Color g = GREEN;  public static void main( String[] argv)  { System.out.println( GREEN); }  }  The class Beta and the enum Color are in different packages.  Which two code fragments, inserted individually at line 2 of the Beta declaration, will allow this code to compile?()

    • A、 import sun.scjp.Color.*;
    • B、 import static sun.scjp.Color.*;
    • C、 import sun.scjp.Color; import static sun.scjp.Color.*;
    • D、 import sun.scjp.*; import static sun.scjp.Color.*;
    • E、 import sun.scjp.Color; import static sun.scjp.Color.GREEN;

    正确答案:C,E

  • 第12题:

    单选题
    enum color{red,green,yellow=5,white,black};定义了一枚举类型。编译程序为值表中各标识符分配的枚举值依次为()。
    A

    1、2、3、4、5

    B

    0、1、5、2、3

    C

    0、1、5、6、7

    D

    3、4、5、6、7


    正确答案: A
    解析: 暂无解析

  • 第13题:

    以下选项中不能正确把c1定义成结构体变量的是

    A.typedef struct {int red: int green: int blue; } COLOR; COLOR c1;

    B.struct color c1 {int red int green: int blue; };

    C.struct color {int red , int green : int blue : )cl;

    D.struct {int red; int green; int blue } c1 ;


    正确答案:B
    解析:本题考核的知识点是结构体类型定义。结构体类型的定义格式为:strcut结构体名{成虽说明列表};结构体变量的定义有3种形式:第一种,定义结构体型的同时定义结构体变量,如:strcut结构体名{成员说明列表}变量;选项C属于这种情况,故选项C正确:第二种,先定义一个结构体类型,然后使用该类型来定义结构体变量,如:strcutstudent{成员说明列表}:student变量;选项A属于这种情况,故选项A正确;第三种,定义一个无名称的结构体类型的同时定义结构体变量,如:strcutstudent{成员说明列表}变量;选项D属于这种情况,故选项D正确.所以,4个选项中选项B符合题意。

  • 第14题:

    packagesun.scjp;publicenumColor{RED,GREEN,BLUE}packagesun.beta;//insertcodeherepublicclassBeta{Colorg=GREEN;publicstaticvoidmain(String[]argv){System.out.println(GREEN);}}TheclassBetaandtheenumColorareindifferentpackages.Whichtwocodefragments,insertedindividuallyatline2oftheBetadeclaration,willallowthiscodetocompile?()

    A.importsun.scjp.Color.*;

    B.importstaticsun.scjp.Color.*;

    C.importsun.scjp.Color;importstaticsun.scjp.Color.*;

    D.importsun.scjp.*;importstaticsun.scjp.Color.*;

    E.importsun.scjp.Color;importstaticsun.scjp.Color.GREEN;


    参考答案:C, E

  • 第15题:

    以下选项中不能正确把cl定义成结构体变量的是

    A.typedef struct { int red; int green; int blue; } COLOR; COLOR cl;

    B.struct color cl { int red; int green; int blue; }

    C.struct color { int red; int green; int blue; } cl;

    D.struct { int red; int green; int blue; } cl;


    正确答案:B
    解析:选项A)是把结构体类型改名后定义为变量cl。选项C),D)则是在定义结构体类型时定义变量,而选项B)不符合结构体类型定义的语法规则。

  • 第16题:

    以下选项中不能正确把c1定义成结构体变量的是

    A.typedef struct { int red; int green;; int blue; }COLOR; COLOR cl;

    B.struct color cl { int red; int green; int blue; };

    C.struet color { int red; int green; int blue; }c1;

    D.struct { int red; int green; int blue; }cl;


    正确答案:B
    解析:结构体类型的定义格式为:
      stract结构体名
      成员说明列表};
      结构体变量的定义有3种形式:第一种,定义结构体类型的同时定义结构体变量,如: street结构体名{成员说明列表}变量;第二种,先定义一个结构体类型,然后使用该类型来定义结构体变量,如:strect student{成员说明列表};student变量;第三种,定义一个无名称的结构体类型的同时定义结构体变量,如:strect student{成员说明列表}变量;。

  • 第17题:

    下列选项中不能正确定义结构体的是_______。

    A.typedef struct

    B.struct color cl {int red; {int red; int green; int green; int blue; int blue; }COLOR; }; COLOR cl;

    C.struct color

    D.struct {int red; {int red; int green; int green; int blue; int blue; }cl; }cl;


    正确答案:B
    解析:将一个变量定义为标准类型与定义为结构体类型不同之处在于:后者不仅要求指定变量为结构体类型,而且要求指定为某一特定的结构体类型(例如,struct color),不能只指定结构体名。其中可以不出现结构体名,答案D就是缺省结构体名的隋况。而变量名歹婊必须放在成员列表后面,所以B答案不能正确将cl定义为结构件变量。

  • 第18题:

    对于这样的一个枚举类型:

    enum Color:byte

    {

    Red,

    Green,

    Blue,

    Orange

    }


    正确答案:
    答:string[] ss=Enum.GetNames(typeof(Color));
         byte[] bb=Enum.GetValues(typeof(Color));

  • 第19题:

    阅读以下说明和 Java 代码,填补代码中的空缺,将解答填入答题纸的对应栏内。 【说明】 设计 RGB 方式表示颜色的调色板,进行绘图。其类图如图 6-1 所示。该程序的 Java代码附后。图6-1 类图

    【Java 代码】 //颜色类 class MyColor { private int red ,green, blue; public MyColor( ) { red = o; green = 0; blue = 0; } public MyColor(int red ,int green ,int blue) { this.red = red; this.green = green; this.blue = blue; } //其他方法略 public String toString( ) { return "Red: " + red + "\tGreen: " + green + "\tBlue " + blue; } } //调色板类 class Palette { public int number; / /颜色数 private (1)palette; //颜色表 public Palette( ) { number = 256; palette = new MyColor[number); } public Palette(MyColor[] palette ,int number) { (2)= number; (3)= palette; } //其他方法略 public String toString( ) { String str = ""; for (int i = 0; i < number; i++) { str +=i+ " : " + palette[i] + "\n"; } return str; } //绘图类 class Drawing { public (4) int COLORNUMBER = 16; public static void main(String[] args) { Palette palette; int red ,green ,blue; MyColor[] color = new MyColor[COLORNUMBER]; for (int i = 0; i < COLORNUMBER; i++) { red = (int) (Math.random( ) * 256); green = (int) (Math.random( ) * 256); blue = (int) (Math.random( ) * 256); color [i] = (5) (red ,green ,blue); } palette = new Palette(color ,COLORNUMBER); System.out.println(palette); } }


    正确答案:(1) MyColor[]
    (2) this.number
    (3) this.palette
    (4) static final
    (5) new MyColor

  • 第20题:

    以下CSS选择符定义中,______属于类选择符。

    A.P{color:red; font-size:12pt}
    B.p.blue{color:blue}
    C.#Red{color:red;)
    D.PEM {background: yellow}

    答案:B
    解析:
    本题考查CSS的基础知识。CSS(Cascading Style Sheets,层叠样式表,简称为样式表)是用于(增强)控制网页样式并允许将样式信息与网页内容分离的一种标记性语言。在CSS基本语法结构中,样式表的结构为:选择符{属性1:值1;属性2:值2;…}其中,选择符有如下几种形式:(1)HTML标记。任何HTML标记都可以是一个CSS的选择符,如P{color:red;font-size:12pt}。(2)类选择符。一个选择符能有不同的CLASS(类),因而允许同一元素有不同的样式。格式如下:标记名:类名{属性1:值1;属性2:值2;…}(3)ID选择符。ID选择符个别地定义每个元素的成分。这种选择符应该尽量少用,因为它具有一定的局限。一个ID选择符的指定要有指示符“#”在名字前面。(4)关联选择符。关联选择符是用空格隔开的两个或更多的单一选择符组成的字符串。这些选择符可以指定一般属性,而且因为层叠顺序的规则,它们的优先权比单一的选择符大。

  • 第21题:

    The traffic lights were red when the driver reached them.To the surprise of his passenger,the ear did not slow down.Unexpectedly the passenger was thrown forward in the vehicle as the driver put on his brakes at the last moment.The car stopped just in time.
    "Sorry,I didn't notice the light.I thought it was green until I saw that it was the top light which was shining."
    This strange story is quite true.About ten men in every hundred are color blind in some way;women are luckier--only about one in two hundred suffers from color blindness.
    In some cases,a man may not be able to see deep red.He may think that red,orange and yellow are all the same as green.
    People often like one color more than others.Blue is the color of the sky and sea.Green makes us think of fields and trees.Red is the color of blood and makes some people think of danger.Black is the color of night.In the dark we cannot see what is around us so we are sometimes afraid of the unknown and do not like black as a color.

    Among the traffic lights,red light is placed__.

    A.at the bottom
    B.in the middle
    C.at the top
    D.below the green light

    答案:C
    解析:
    参见第二段。

  • 第22题:

    public class Ball {  public enum Color { RED, GREEN, BLUE };  public void foo() {  // insert code here  { System.out.println(c); }  }  }  Which code inserted at line 14 causes the foo method to print RED, GREEN, and BLUE?() 

    • A、 for( Color c : Color.values())
    • B、 for( Color c = RED; c <= BLUE; c++)
    • C、 for( Color c; c.hasNext() ; c.next())
    • D、 for( Color c = Color[0]; c <= Color[2]; c++)
    • E、 for( Color c = Color.RED; c <= Color.BLUE; c++)

    正确答案:A

  • 第23题:

    enum color{red,green,yellow=5,white,black};定义了一枚举类型。编译程序为值表中各标识符分配的枚举值依次为()。

    • A、1、2、3、4、5
    • B、0、1、5、2、3
    • C、0、1、5、6、7
    • D、3、4、5、6、7

    正确答案:C