Which code segment should you use?

You are implementing an ASP.NET page.
Client-side script requires data.
Your application includes a class named Person with a Name property of type string.
The code-behind file of the page includes the following code segment.

public string JsonValue;
List<Person> people = GetPeopleList();
JavaScriptSerializer json = new JavaScriptSerializer();

You need to use the JavaScriptSerializer class to serialize only the Name property of each item in the people list.
Which code segment should you use?

You are implementing an ASP.NET page.
Client-side script requires data.
Your application includes a class named Person with a Name property of type string.
The code-behind file of the page includes the following code segment.

public string JsonValue;
List<Person> people = GetPeopleList();
JavaScriptSerializer json = new JavaScriptSerializer();

You need to use the JavaScriptSerializer class to serialize only the Name property of each item in the people list.
Which code segment should you use?

A.
JsonValue = json.Serialize(people.Select(p => p.Name));

B.
var names = from person in people
select person;
JsonValue = “{” + json.Serialize(names) + “}”;

C.
JsonValue = json.Serialize(people.SelectMany( p =>Name.AsEnumerable()));

D.
var names = from person in people
select person;
JsonValue = json.Serialize(names);



Leave a Reply 0

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