Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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.
C#
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.
C#
var names = from person in people
select person;
JsonValue = "{" + json.Serialize(names) + "}";

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

D.
C#
var names = from person in people
select person;
JsonValue = json.Serialize(names);</person>
Posted
Updated 9-Jan-13 2:16am
v2
Comments
Sandeep Mewara 9-Jan-13 8:17am    
And what do you think it should be?

Tried yourself?
Tejal S 9-Jan-13 8:22am    
A. i guess

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900