Search Placementyogi.com
 

C# Enumerations - Basic .NET Objective Questions

1

Enumeration (enum) in c# is a reference type.

A. True
B. False
See Answer & Explanation Lets Discuss
Correct answer is : B
Explanation

As shown in the data type hierarchy in Data Type tutorial, enumeration is a value type.

 
2

Which of the following statements is correct about enum in C#? (Multiple Choice)

A.

The default value of first element of an enum is 0.

B.

If there is no access specifier, enum is treated as public.

C.

An enum can be declared inside a class, struct, interface or namespace.

D.

Values assigned to enum elements must always begin with 0.

E.

All of the above

See Answer & Explanation Lets Discuss
Correct answer is : A,B,C
Explanation

No explanation available. Let's Discuss

 
3

Will the below C# program execute correctly?

using System;
public class Yogi
{
    static byte a = 10;
    static byte b = 20;
    static byte c = 30;
    enum fruit
    {
        apple = a,
        orange = b,
        mango = c
    }
}
A. Yes
B. No
See Answer & Explanation Lets Discuss
Correct answer is : B
Explanation

Variables cannot be assigned to enum elements.

You will get the following compiler error:

The expression being assigned to 'MainClass.color.apple' must be constant.

 
4

What is the output of the following C# program?

using System;
public class Yogi
{
    enum fruit
    {
        apple,
        orange,
        mango
    }
    public static void Main(String[] args)
    {
        Console.WriteLine(fruit.mango);
    }
}
A.

2

B.

3

C.

mango

D.

None of these

See Answer & Explanation Lets Discuss
Correct answer is : C
Explanation

No explanation available. Let's Discuss

 
5

What is the output of the following C# program?

using System;
public class Yogi
{
    enum fruit
    {
        apple=1,
        orange,
        mango
    }
    public static void Main(String[] args)
    {
        Console.Write((int)fruit.apple + " ");
        Console.Write((int)fruit.orange + " ");
        Console.Write((int)fruit.mango);
    }
}
A.

1 orange mango

B.

apple orange mango

C.

1 2 3

D.

None of these

See Answer & Explanation Lets Discuss
Correct answer is : C
Explanation

enum values are incremented by 1 every time based on the first element value. Since here first element's value is 1 so it is incremented to 2 then 3.

 
 

Banner to LogicGuns.com

Hide Page Information

C# Enumerations - Basic Objective Questions and Answers with Explanation

Here you can find basic level C# enumerations interview questions with answers and explanation.

Why Enumerations in C#?

In this section you can learn and practice different types of basic level questions with answers on enumerations to improve your skills in order to face the interviews, competitive examinations and various entrance tests with full confidence.

Where can I get C# Enumerations Basic Questions and Answers with Explanation?

PlacementYogi provides you lots of fully solved basic level enumerations questions and answers with explanation. Fully solved examples with detailed answer description, explanation are given and it would be easy to understand. All students, freshers can download quiz questions with answers as PDF files and eBooks.

Where can I get Basic Level C# Enumerations Interview Questions and Answers (objective type, multiple choice)?

Here you can find objective type basic enumerations questions and answers for interview and entrance examination. Multiple choice and TRUE or FALSE type and YES or NO type questions are also provided.