PrepAway - Latest Free Exam Questions & Answers

Which code segment should you use?

You create a class library that is used by applications in three departments of Domain.com.
The library contains a Department class with the following definition.
public class Department {
public string name;
public string manager;
}
Each application uses a custom configuration section to store department-specific values in the application configuration file
as shown in the following code.

Hardware
Certkiller

You need to write a code segment that creates a Department object instance by using the field values retrieved from the application configuration file.
Which code segment should you use?

PrepAway - Latest Free Exam Questions & Answers

A.
public class deptElement : ConfigurationElement {
protected override void DeserializeElement(XmlReader reader, bool serializeCollectionKey) {
Department dept = new Department();
dept.name = ConfigurationManager.AppSettings[“name”];
dept.manager = ConfigurationManager.AppSettings[“manager”]; return dept;
}
}

B.
public class deptElement: ConfigurationElement {
protected override void DeserializeElement(XmlReader reader, bool serializeCollectionKey) {
Department dept = new Department();
dept.name = reader.GetAttribute(“name”);
dept.manager = reader.GetAttribute(“manager”);
}
}

C.
public class deptHandler : IConfigurationSectionHandler { public object Create(object parent, object configContext, System.Xml.XmlNode section) {
Department dept = new Department();
dept.name = section.SelectSingleNode(“name”).InnerText;
dept.manager = section.SelectSingleNode(“manager”).InnerText; return dept;
}
}

D.
public class deptHandler : IConfigurationSectionHandler { public object Create(object parent, object configContext, System.Xml.XmlNode section) {
Department dept = new Department();
dept.name = section.Attributes[“name”].Value;
dept.manager = section.Attributes[“manager”].Value;
return dept;
}
}

2 Comments on “Which code segment should you use?


Leave a Reply