creating & using libraries (dll)

Class Libraries in Visual Studio


Create a Library
To add a library to a solution right-click on solution in solution explorer add new project
New Project Class Library creates a library project provides namesapce provides a class must be public
Create methods within the provided class namespace WyattJB { public class PrimeClass { // methods go HERE } }

Referencing the Library
Can use for windows OR console project ** create code that is not dependent on either avoid console ops or windows controls dependencies
Must create a reference to library!!! In solution explorer right-click on project that wants to use the library add reference choose class library project

Using the Methods in the Library
Method MUST be static (do not need to create an instance)... (for now) namespace WyattJB { public class MyClass { public static int IncreaseByHundred(int num) { int newNum; newNum = num + 100; return newNum; } } }
AFTER creating a reference in a project, call the library method as such: int answer = WyattJB.MyClass.IncreasByHundred(num));

Refactoring
Refactoring is a continuous process improving the structure of your code - NOT the functionality. refactoring defined refactoring manifesto! One form of refactoring is renaming variables and/or methods - Highlight name to be changed - Right click - Choose Refactor Another form of refactoring is moving statements into a method to - reduce duplication - make more readable - reduce complexity
To create a new method easily in Visual Studio: Put the coursor at the point you want to insewrt the call. Insert the call: GetUserInput( "Enter an Integer Value"); A small "underline" will appear under the first chatracter of the call Click on the underline Click on "Generate method stub" The method will be inserted Some refactored methods will be put into libraries