This question was asked in a technical test recently:
Which of these is a Value Type:
int idouble dstruct S
{
int a;
string b;
}enum Test
{
a,
b,
c,
d
}I thought that it was a trick question; int and double are structs, and structs are ValueTypes, hence all the answers are Value Types. But only one answer was allowed and apparently the "correct" answer was 4) the enum.
Is there anyway that answer 4) can be the only correct answer?
Maybe the authors of the questions have a different definition of value types?
All four answers are value types:
int integer = 0;
Console.WriteLine(integer.GetType().IsValueType); //true
double dbl = 0.0;
Console.WriteLine(dbl.GetType().IsValueType); //true
S s = new S();
Console.WriteLine(s.GetType().IsValueType); //true
Test t = Test.a;
Console.WriteLine(t.GetType().IsValueType); //true
They are all value types. See the value types table on MSDN.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With