For each of the following statements, select Yes if the statement is true…

HOTSPOT
You are reviewing the following code:

For each of the following statements, select Yes if the statement is true. Otherwise, select No.

HOTSPOT
You are reviewing the following code:

For each of the following statements, select Yes if the statement is true. Otherwise, select No.

Answer:



Leave a Reply 25

Your email address will not be published. Required fields are marked *


Dhruv

Dhruv

The answer should be

No

Yes

Yes

Dhruv

Dhruv

I take it back. The answer given is correct.

It should be

Yes

No

No

koernomop

koernomop

Answer is
Yes – user.UserGroup = Group.Users | Group.Managers;
// see FlagsAttribute
Yes – user.UserGroup = Group.Administrators;
var b = user.UserGroup == Group.Administrators;
// b is true
Yes – user.UserGroup = Group.Supervisors;
var c = user.UserGroup < Group.Administrators;
// c is true because 2 < 8

karfik

karfik

Three yeses are correct. Tried with simple console application.

Farhat

Farhat

How can all answer are correct?
can you send me the console code?

Mr D

Mr D

Yes
Yes
Yes

Tested by console

宾宾

宾宾

三个答案都是正确的。

al adeeb

al adeeb

Can someone explain the second one please, why is that “NO”.

Deno

Deno

Um den Namespace anzugeben müsste es wie folgt aussehen: “[DataContract(Namespace=”Individual”)]”

Deno

Deno

Because with “[DataContract (Name =” Individual “)]” is specified name.

To specify the namespace, it would look like this: “[DataContract (Namespace =” Individual “)]”

ASV

ASV

No,
Yes,
Yes.

ASV

ASV

Yes, Yes, Yes.

Gleb

Gleb

1) Yes, because Group is enum with FlagAttribute
2) Yes, because only Administrator = 8 and 8 == 8 is true
3) Yes, becaues only Supervisor = 2 and 2 < 8 is true

Mahbub

Mahbub

YES -> this one is confusing. user can be part of new group with enum 3(Group.Users | Group.Supervisors)
YES
YES

Farhat

Farhat

Please can any one give the correct answer to me?

Above comments are creating confusing.

Jiping Wang

Jiping Wang

Yes,
Yes,
Yes,
all checked in Visual Studio 2015.

Elvis

Elvis

I typed this code for check whether first case works . In this case it`s not working. The code output NO. Other cases are YES .

public class User
{
public Group UserGroup { get; set; }
}

[FlagsAttribute()]
public enum Group
{
Users=1,
Supervisors=2,
Managers=4,
Administrators=8
}
class Program
{
static void Main(string[] args)
{

// The first case
User us1 = new User();

us1.UserGroup = Group.Supervisors | Group.Users;

bool checkVar = us1.UserGroup==Group.Supervisors;

if (checkVar)
{
Console.WriteLine(“YES”);
}
else { Console.WriteLine(“NO”); }

//The second case
User us2 = new User();
us2.UserGroup = Group.Administrators;
if (us2.UserGroup == Group.Administrators)
{
Console.WriteLine(“YES”);
}
else { Console.WriteLine(“NO”); }

// The third case
User us3 = new User();
us3.UserGroup = Group.Supervisors;
if (us3.UserGroup < Group.Administrators)
{
Console.WriteLine("YES");
}
else { Console.WriteLine("NO"); }
Console.ReadLine();
}
}

Artem

Artem

For true test first case you must check
if(us1.UserGroup == Group.Supervisors && us1.UserGroup == Group.Users)
but result not changed.

Google

Google

Please go to the internet sites we stick to, including this one, because it represents our picks from the web.

Sbuse

Sbuse

Yes – Clear
No – The default namespace is “http://tempuri.org”
Yes – It will have a default value even if is null

Artem

Artem

3 NO. I check in VS. Field with [DataMember(EmitDefaultValue = false)] was skipped with default value (null for string).

harsh

harsh

Tested with the visiual studio :
User u = new User();
u.UserGroup = Group.Administrator | Group.Users;
Console.WriteLine((u.UserGroup == Group.Administrator).ToString());
User u1 = new User();
u1.UserGroup = Group.Administrator;
Console.WriteLine(u1.UserGroup==Group.Administrator);

User u2 = new User();
u2.UserGroup = Group.Super;
Console.WriteLine(u2.UserGroup< Group.Administrator);
Console.Read();

Got answer :
False
True
True
means
NO
YES
YES

kirmani

kirmani

Yes, Yes, Yes
using System;

[Flags]
public enum UserGroup
{
Users = 1,
Supervisor = 2,
manager = 4,
Administrator = 8
}

public class User
{
public UserGroup Group;
}
public class Flags
{
public static void Main(string[] args)
{
User usr = new User()
{
Group = UserGroup.Administrator
};

if (usr.Group == UserGroup.Administrator)
{
Console.WriteLine(“User1 is an administrator”);
}

User usr2 = new User() { Group = UserGroup.Supervisor };

if (usr2.Group < UserGroup.Administrator)
{
Console.WriteLine("User2 is an Supervisor");
}

User usr3 = new User() { Group = UserGroup.Administrator | UserGroup.manager };

if (usr3.Group.HasFlag( UserGroup.manager))
{
Console.WriteLine("User3 is an Manager");
}

Console.ReadKey();
}
}