98-372 · Question #85
Consider the following scenario: Ryan has just started an internship with Company Inc., as a developer. He is updating the company's inventory system to use barcode and GPS technologies for improving
The correct answer is C. InventorySystem.Package. The fully qualified name of Ryan's new Package class is InventorySystem.Package. By default, Visual Studio creates a namespace with the same name as the project name. Namespaces and types have unique titles described by fully qualified names that specify a logical hierarchy. For
Question
Consider the following scenario:
Ryan has just started an internship with Company Inc., as a developer. He is updating the company's inventory system to use barcode and GPS technologies for improving the package tracking. Ryan's manager asked him to use classes from the company's existing inventory system as much as possible to save time because the older code has been tested thoroughly. The classes are part of a Microsoft Visual Studio project called InventorySystem; Ryan's Visual Studio project is called TrackingSystem. Ryan is having problems because some of his classes, such as Package, Barcode, and Destination, have names that already exist in the InventorySystem. However, both projects use the default namespaces defined by Visual Studio .NET 2010 when the projects were created. Which of the following is most likely the fully qualified name of Ryan's new Package class?
Options
- ASystem.Package
- BWindows.Package
- CInventorySystem.Package
- DSystem.Default.Package
How the community answered
(53 responses)- A9% (5)
- B4% (2)
- C81% (43)
- D6% (3)
Explanation
The fully qualified name of Ryan's new Package class is InventorySystem.Package. By default, Visual Studio creates a namespace with the same name as the project name. Namespaces and types have unique titles described by fully qualified names that specify a logical hierarchy. For instance, the statement X.Y implies that X is the name of the namespace or type, and Y is nested within it. Consider the following example that contains nested classes and namespaces. The fully qualified name is specified as a comment following each entity. namespace A1 // A1 class B1 // A1.B1 class B2 // A1.B1.B2 namespace A2 // A1.A2 class B2 // A1.A2.B2 In the above code segment: The namespace A1 is a member of the global namespace. Its fully qualified name is A1. The namespace A2 is a member of A1. Its fully qualified name is A1.A2. The class B1 is a member of A1. Its fully qualified name is A1.B1. The class name B2 is used two times in this code. However, the fully qualified names are unique. The first instance of B2 is declared within B1; therefore, its fully qualified name is A1.B1.B2. The second instance of B2 is declared within the namespace A2; therefore, its fully qualified name is A1.A2.B2. Using the above code segment, a new class member can be added named B3 to the namespace A1.A2 as follows: class B3 // A1.A2.B3 Use :: to reference a namespace alias or global:: to reference the global namespace and . to qualify types or members. It is incorrect to use :: with an alias that references a type rather than a namespace. For example: using Alias = System.Console; static void Main() //Alias::WriteLine("Hello"); Alias.WriteLine("Hello"); Keep in mind that the word global is not a predefined alias so global.X does not have any special meaning. It obtains a special meaning only when it is used with ::. Compiler warning CS0440 is generated if an alias named global is defined because global:: always references the global namespace and not an alias. Consider the following example, it generates the warning: using global = System.Collections; // Warning Using :: with aliases is a good idea and protects against the unexpected introduction of additional types. For instance, consider the following example: using Alias = System; namespace Library public class C : Alias.Exception { } The code works, but if a type named Alias were to later be introduced, Alias, would bind to that type instead. Using Alias::Exception ensures that Alias is considered as a namespace alias and
Topics
Community Discussion
No community discussion yet for this question.