C# Programming - Enumerations - Discussion
Discussion Forum : Enumerations - General Questions (Q.No. 7)
7.
An enum that is declared inside a class, struct, namespace or interface is treated as public.
Discussion:
3 comments Page 1 of 1.
K2u2007 said:
1 decade ago
An enum has default modifier as public.
A class has default modifiers as Internal . It can declare members (methods etc) with following access modifiers:
public
internal
private
protected internal
An interface has default modifier as public
A struct has default modifier as Internal and it can declare its members (methods etc) with following access modifiers:
public
internal
private
A methods, fields, and properties has default access modifier as "Private" if no modifier is specified.
Members of interface and enum are always public by default, the modifier must not be applied in those contexts.
The individual access modifiers are defined in the C# Language Specification as:
private Access limited to the containing type.
internal Access limited to this program.
public Access not limited.
protected Access limited to the containing class or types derived from the containing class.
protected internal Access limited to this program or types derived from the containing class.
Note: the term this program can be replaced by the containing assembly.
A class has default modifiers as Internal . It can declare members (methods etc) with following access modifiers:
public
internal
private
protected internal
An interface has default modifier as public
A struct has default modifier as Internal and it can declare its members (methods etc) with following access modifiers:
public
internal
private
A methods, fields, and properties has default access modifier as "Private" if no modifier is specified.
Members of interface and enum are always public by default, the modifier must not be applied in those contexts.
The individual access modifiers are defined in the C# Language Specification as:
private Access limited to the containing type.
internal Access limited to this program.
public Access not limited.
protected Access limited to the containing class or types derived from the containing class.
protected internal Access limited to this program or types derived from the containing class.
Note: the term this program can be replaced by the containing assembly.
Nicholas Mahbouby said:
1 decade ago
Answer A is wrong. An enum declared inside a class or struct is private and is only accessible from within the class or struct. The following code will produce a compilation error.
class A
{
enum Colour
{
Red,
Green,
Blue
}
}
class Program
{
static void Main(string[] args)
{
A.Colour colour = A.Colour.Red;
}
}
class A
{
enum Colour
{
Red,
Green,
Blue
}
}
class Program
{
static void Main(string[] args)
{
A.Colour colour = A.Colour.Red;
}
}
Shaila said:
1 decade ago
By default enum is public.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers