Presentation is loading. Please wait.

Presentation is loading. Please wait.

SSE693 C# and.NET Dr. MacNeil Summer 2005 Jay Clary / Lance Hilliard Team Project 3.

Similar presentations


Presentation on theme: "SSE693 C# and.NET Dr. MacNeil Summer 2005 Jay Clary / Lance Hilliard Team Project 3."— Presentation transcript:

1 SSE693 C# and.NET Dr. MacNeil Summer 2005 Jay Clary / Lance Hilliard Team Project 3

2 Purpose: To illustrate Topics found in Chapters 9-11 of Professional C# Chapter 9 Array Lists, Collections, Dictionaries Chapter 10 Reflection Chapter 11 Exceptions

3 Theory of Operation The following files are located in the TeamProject3ClaryHilliard file: ArrayLists.cs Collections.cs DeveloperAttributes.cs Dictionaries.cs Exceptions.cs Reflections.cs

4 Theory of Operation ArrayLists.cs contains our example of Array Lists from Chapter 9 page 240. First we created a sample class, Points, and then we instantiated the array list by declaring it with a capacity of 20. We used the add() method to fill the array lists. Finally, we use the arraylist.count method to get how many elements are in the array list and print their contents.

5 Theory of Operation Collections.cs contains our example of Collections from Chapter 9 pages 241 through 244. First, we define the Parser class and implement the IEnumerable interface. Then we defined the Parser method and it receives as inputs a string and delimiters so it will know what to look for in each string. Next, we defined the ParserEnumerator class and inherited the IEnumerable class again. Finally, we set up our MoveNext, Current and Reset methods to work with our example (describing how to track the parsers position in the file).

6 Developer Attributes and Reflection - Theory of Operation Developer Attributes and Reflection are illustrated in the files DeveloperAttributes.cs and Reflections.cs. To demonstrate the user of Attributes we begin by using the special atribute syntax to define the appropriate AttributeUsage. Then we define a class that is derived from System.Attribute. This class contains a number of member properties to extract the information from the class. We finish the class by defining the private storage to hold the data. At the bottom of DeveloperAttributes.cs, we use the special Attribute syntax to add 3 DeveloperAttribute entries that will exists as part of the myAttributeTest class. To illustrate how this information is retrieved from a class, we instantiate the class Reflections which will bring into scope an instance of myAttributeTest. Once instantiated, myAttributeTest is called upon to present its MemberInfo. Using this, we can invoke GetCustomAttributes(). Once obtained, we can iterate through each object and access the internal Attributes we stored earlier as part of myAttributeTest.

7 Directories - Theory of Operation We will illustrate the use of Dictionaries in the file Dictionaries.cs. We demonstrate Dictionaries by created a class used to hold a UserID. This is the data that we will use as the Hash key for access into the Dictionary. The UserID class overrides the GetHash(), ToString() and Equals() methods so that the class will be properly supported by the underlying.NET framework. To make the example more realistic, we also create another class called UserData that stores an instance of the UserID class and some additional data about the user. To make use of dictionaries, we then instantiate a HashTable class along with several instances of both UserID and UserData. This newly created data is inserted into the HashTable. We can now search the Dictionary for any instance of data that we desire. A loop is provided that allows the user to input UserIDs that will be hashed and located in the Dictionary. If the data is found, it will be presented, if not and explanatory message will be shown. The user may enter ‘Q’ at any time to quit the Dictionary demonstration.

8 Theory of Operation Exceptions.cs contains our example of exceptions from Chapter 11. We created an exception class and inherited ApplicationException. Then we created our own custom exception, “Attempt was made to divide by zero…” Then we implemented a sample use of try, catch and throw.

9 Compilation and Execution To build and execute the program, follow the steps outlined below. First create a directory on Drive C called CSharp i.e. C:\CSharp Unzip the file TeamProject3ClaryHilliard.zip into the CSharp directory. One sub-directory will be created that contains the eight files that demonstrate the important topics from the assigned reading. Navigate to the directory of choice and Double click on the.sln file. This will launch the Microsoft C# development environment and load the project. Click the Run Icon and observe the results.

10 Run Results Array Lists

11 Run Results Collections:

12 Run Results Attributes and Reflection:

13 Run Results Dictionary:

14 Run Results Exceptions:


Download ppt "SSE693 C# and.NET Dr. MacNeil Summer 2005 Jay Clary / Lance Hilliard Team Project 3."

Similar presentations


Ads by Google